def _checkAtom(self): """Checks if menu item is atom menu class """ session = core.Kernel.session() self._skin = "MenuItem" self._color = "#ffffff" if sc_utils.checkIncToSets(session, self._getScAddr(), [keynodes.ui.atom_command], sc.SC_CONST): self.atom = True self._icon_name = sc_utils.getImageIdentifier(session, keynodes.ui.atom_command) # check if it is a question command if sc_utils.checkIncToSets(session, self._getScAddr(), [keynodes.ui.question_command], sc.SC_CONST): self.question = True self._icon_name = sc_utils.getImageIdentifier(session, keynodes.ui.question_command) return elif sc_utils.checkIncToSets(session, self._getScAddr(), [keynodes.ui.noatom_command], sc.SC_CONST): self.atom = False self._icon_name = sc_utils.getImageIdentifier(session, keynodes.ui.noatom_command) return else: #object self.atom = False self.question = False return global logManager logManager.logWarning("Unknown atom class for a menu item '%s'" % self.getCaption())
def calculate_graph_prop(_params, _segment): kernel = core.Kernel.getSingleton() session = kernel.session() segment = kernel.segment() # check type question = session.search_one_shot(session.sc_constraint_new(sc_constants.CONSTR_5_f_a_a_a_f, keynodes.questions.initiated, sc.SC_A_CONST, sc.SC_N_CONST, sc.SC_A_CONST, _params), True, 5) assert question is not None question = question[2] global graph_prop_calculators for question_type, calculator, relation in graph_prop_calculators: # check command type if sc_utils.checkIncToSets(session, question, [question_type], sc.SC_CONST): graph = session.search_one_shot(session.sc_constraint_new(sc_constants.CONSTR_3_f_a_a, question, sc.SC_A_CONST, sc.SC_N_CONST), True, 3) if graph is None: return graph = graph[2] if not sc_utils.checkIncToSets(session, graph, [graph_keynodes.Common.graph], sc.SC_CONST): return g = Graph(segment, graph) g.makeNxGraph() result = calculator(g.graphNx) if result is None: raise RuntimeWarning("Calculator can't calculate value") value = sc_utils.createNodeElement(session, segment, sc.SC_CONST) bin_rel = sc_utils.createPairBinaryOrientFull(session, segment, graph, value, sc.SC_CONST) a = sc_utils.createPairPosPerm(session, segment, relation, bin_rel[0], sc.SC_CONST) elements = translate_value(session, segment, value, result) elements.extend([value, graph, a, relation]) elements.extend(bin_rel) answer = sc_utils.createNodeElement(session, segment, sc.SC_CONST) for el in elements: sc_utils.createPairPosPerm(session, segment, answer, el, sc.SC_CONST) sc_utils.makeAnswer(session, segment, question, answer)
def mouse_button(_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] pressed = False # check if it's a mouse move button press command if sc_utils.checkIncToSets(session, command, [keynodes.ui.cmd_mouse_button_press], sc_core.pm.SC_CONST): pressed = True elif not sc_utils.checkIncToSets(session, command, [keynodes.ui.cmd_mouse_button_release], sc_core.pm.SC_CONST): return # need to get button id button = session.search_one_shot( session.sc_constraint_new(sc_core.constants.CONSTR_3_f_a_a, command, sc_core.pm.SC_A_CONST, sc_core.pm.SC_N_CONST), True, 3) if button is None: raise RuntimeError( "There are no button id for mouse button command %s" % str(command)) button = button[2] button_id = -1 # translate button sc-addr into ois button id if button.this == keynodes.ui.mouse_button_left.this: button_id = ois.MB_Left elif button.this == keynodes.ui.mouse_button_right.this: button_id = ois.MB_Right elif button.this == keynodes.ui.mouse_button_middle.this: button_id = ois.MB_Middle else: raise RuntimeError("Unknown mouse button id for command %s" % str(command)) cmd = commands.MouseButton(button_id, 0.1, pressed) cmd.eventFinished = finish_callback cmds[cmd] = command cmd.start()
def keyboard_button(_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] pressed = False # check if it's a mouse move button press command if sc_utils.checkIncToSets(session, command, [keynodes.ui.cmd_keyboard_button_press], sc_core.pm.SC_CONST): pressed = True elif not sc_utils.checkIncToSets(session, command, [keynodes.ui.cmd_keyboard_button_release], sc_core.pm.SC_CONST): return # need to get button id button = session.search_one_shot( session.sc_constraint_new(sc_core.constants.CONSTR_3_f_a_a, command, sc_core.pm.SC_A_CONST, sc_core.pm.SC_N_CONST), True, 3) if button is None: raise RuntimeError( "There are no button id for keyboard button command %s" % str(command)) button = button[2] button_id = -1 for i in keynodes.ui.keyboard.dictionary: if button.this == i.this: button_id = keynodes.ui.keyboard.dictionary[i] if button_id == -1: raise RuntimeError("Unknown keyboard button id for command %s" % str(command)) cmd = commands.KeyboardButton(button_id, 0.1, pressed) cmd.eventFinished = finish_callback cmds[cmd] = command cmd.start()
def mouse_button(_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] pressed = False # check if it's a mouse move button press command if sc_utils.checkIncToSets(session, command, [keynodes.ui.cmd_mouse_button_press], sc_core.pm.SC_CONST): pressed = True elif not sc_utils.checkIncToSets(session, command, [keynodes.ui.cmd_mouse_button_release], sc_core.pm.SC_CONST): return # need to get button id button = session.search_one_shot(session.sc_constraint_new(sc_core.constants.CONSTR_3_f_a_a, command, sc_core.pm.SC_A_CONST, sc_core.pm.SC_N_CONST), True, 3) if button is None: raise RuntimeError("There are no button id for mouse button command %s" % str(command)); button = button[2] button_id = -1 # translate button sc-addr into ois button id if button.this == keynodes.ui.mouse_button_left.this: button_id = ois.MB_Left elif button.this == keynodes.ui.mouse_button_right.this: button_id = ois.MB_Right elif button.this == keynodes.ui.mouse_button_middle.this: button_id = ois.MB_Middle else: raise RuntimeError("Unknown mouse button id for command %s" % str(command)) cmd = commands.MouseButton(button_id, 0.1, pressed) cmd.eventFinished = finish_callback cmds[cmd] = command cmd.start()
def _updateView(self): if self.needLocalizationUpdate: session = self.kernel.session() _caption = "#aaaaaaunknown" # get question class it = session.create_iterator( session.sc_constraint_new( sc_core.constants.CONSTR_3_a_a_f, sc_core.pm.SC_N_CONST, sc_core.pm.SC_A_CONST | sc_core.pm.SC_POS, self._getScAddr()), True) while not it.is_over(): _class = it.value(0) if sc_utils.checkIncToSets(session, _class, [keynodes.questions._class], sc_core.pm.SC_CONST): _caption = sc_utils.getLocalizedIdentifier( core.Kernel.session(), _class)[0] if len(_caption) == 0: _caption = "#aaaaaaunknown" break it.next() self.setText(_caption) self.needLocalizationUpdate = False objects.ObjectOverlay._updateView(self)
def updateList(self): """Updates list of windows """ # remove old buttons self.clearList() # get output arcs from format import sc_core.constants, sc_core.pm import suit.core.sc_utils as sc_utils session = core.Kernel.session() it = session.create_iterator( session.sc_constraint_new( sc_core.constants.CONSTR_3_f_a_a, self.format, sc_core.pm.SC_A_CONST, sc_core.pm.SC_N_CONST ), True, ) while not it.is_over(): # check if founded node designate sc-window if sc_utils.checkIncToSets(session, it.value(2), [keynodes.ui.sc_window], sc_core.pm.SC_A_CONST): button = self.buttonContainer.createWidgetT( "Button", "Button", mygui.IntCoord(0, 0, 0, 0), mygui.Align() ) button.setCaption(unicode(session.get_idtf(it.value(2)))) button.subscribeEventMouseButtonClick(self, "_onButtonClick") id = str(button) button.setUserString("id", id) self.widget2addr[id] = it.value(2) button.setStateCheck(core.Kernel.getSingleton().haveOutputWindow(it.value(2))) self.buttons.append(button) it.next()
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 updateList(self): """Updates list of windows """ # remove old buttons self.clearList() # get output arcs from format import sc_core.constants, sc_core.pm import suit.core.sc_utils as sc_utils session = core.Kernel.session() it = session.create_iterator( session.sc_constraint_new(sc_core.constants.CONSTR_3_f_a_a, self.format, sc_core.pm.SC_A_CONST, sc_core.pm.SC_N_CONST), True) while not it.is_over(): # check if founded node designate sc-window if sc_utils.checkIncToSets(session, it.value(2), [keynodes.ui.sc_window], sc_core.pm.SC_A_CONST): button = self.buttonContainer.createWidgetT( "Button", "Button", mygui.IntCoord(0, 0, 0, 0), mygui.Align()) button.setCaption(unicode(session.get_idtf(it.value(2)))) button.subscribeEventMouseButtonClick(self, '_onButtonClick') id = str(button) button.setUserString("id", id) self.widget2addr[id] = it.value(2) button.setStateCheck( core.Kernel.getSingleton().haveOutputWindow(it.value(2))) self.buttons.append(button) it.next()
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 parse(self, input, question_node): #производим поиск всех связок отношения координаты* в ответе coord_sheafs = [] res_list = session.search3_f_a_a(input, sc.SC_A_CONST|sc.SC_POS, sc.SC_CONST|sc.SC_NODE) if res_list is not None: for res in res_list: sheaf_node = res[2] is_coord_rel_sheaf = sc_utils.checkIncToSets(session, sheaf_node, [sc_coord_rel_node], sc.SC_A_CONST|sc.SC_POS) if is_coord_rel_sheaf: coord_sheafs.append(sheaf_node) #элементы связки отношения и запоминаем название географического for sheaf in coord_sheafs: obj_node = sc_utils.searchOneShot(session.search5_f_a_a_a_f(sheaf, sc.SC_A_CONST|sc.SC_POS, sc.SC_CONST|sc.SC_NODE, sc.SC_A_CONST|sc.SC_POS, sc_keys.n_1))[2] obj_name = sc_utils.getLocalizedIdentifier(session, obj_node)[0] """obj_class_node = session.search3_a_a_f(sc.SC_CONST|sc.SC_ELMNCLASS, sc.SC_A_CONST|sc.SC_POS, obj_node) if obj_class_node is not None: for el_set in obj_class_node: print sc_utils.getLocalizedIdentifier(session, el_set[0])[0] obj_class_name = sc_utils.getLocalizedIdentifier(session, obj_class_node)[0]""" obj_class_name = "geo_obj" coord_node = sc_utils.searchOneShot(session.search5_f_a_a_a_f(sheaf, sc.SC_A_CONST|sc.SC_POS, sc.SC_CONST|sc.SC_NODE, sc.SC_A_CONST|sc.SC_POS, sc_keys.n_2))[2] #получаем координаты из содержимого узла _cont = session.get_content_const(coord_node) _cont_data = _cont.convertToCont() coords_str = str(_cont_data.d.ptr) #сохраняем сведения об географическом объекте в карту self.parsed_data[obj_class_name + " " + obj_name] = coords_str
def findPlanetTitle(session, planet, language): """ @param session: current workable session @type session: sc_session @param planet: planet which title we are finding @type planet: sc_global_addr @param language: language of title @type language: sc_global_addr @return: title of the planet @rtype: string """ identficationKey = keynodes.common.nrel_identification addr1 = sc_utils.searchOneShotBinPairAttrToNode(session, planet, identficationKey, sc.SC_N_CONST) if addr1 is not None: addr2 = searchPosArcFrom(session, addr1) for addr in addr2: is_spec_lang = sc_utils.checkIncToSets(session, addr, [language], sc.SC_A_CONST) if is_spec_lang is True: content = session.get_content_str(addr) if content is not None: return sc_utils.cp1251ToUtf8(content) return None
def getFormatIcon(self, _format): """Return icon associated with specified format @param _format: sc-node that designate format @type _format: sc_addr @return: Name of texture that contains icon associated to _format, if there are no any icons, then return None """ import suit.core.sc_utils as sc_utils import sc_core.constants as sc_constants import sc_core.pm as sc import ogre.renderer.OGRE as ogre session = core.Kernel.session() icon = None idtf_set = sc_utils.searchOneShotBinPairAttrToNode( session, _format, keynodes.common.nrel_identification, sc.SC_CONST ) if idtf_set is not None: it1 = session.create_iterator( session.sc_constraint_new(sc_constants.CONSTR_3_f_a_a, idtf_set, sc.SC_A_CONST, sc.SC_N_CONST), True ) while not it1.is_over(): if sc_utils.checkIncToSets(session, it1.value(2), [keynodes.common.group_image], sc.SC_CONST): icon = it1.value(2) break it1.next() if icon is None: return None _fmt = sc_utils.getContentFormat(session, icon) assert _fmt is not None _cont = session.get_content_const(icon) assert _cont is not None _cont_data = _cont.convertToCont() data = _cont.get_data(_cont_data.d.size) stream = ogre.MemoryDataStream("%s" % str(self), _cont_data.d.size, False) stream.setData(data) try: img = ogre.Image() img.load(stream, ogre.Image.getFileExtFromMagic(stream)) except: import sys, traceback print "Error:", sys.exc_info()[0] traceback.print_exc(file=sys.stdout) icon_name = "icon_%s" % str(_format) ogre.TextureManager.getSingleton().loadImage(icon_name, "General", img) return icon_name return None
def keyboard_button(_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] pressed = False # check if it's a mouse move button press command if sc_utils.checkIncToSets(session, command, [keynodes.ui.cmd_keyboard_button_press], sc_core.pm.SC_CONST): pressed = True elif not sc_utils.checkIncToSets(session, command, [keynodes.ui.cmd_keyboard_button_release], sc_core.pm.SC_CONST): return # need to get button id button = session.search_one_shot(session.sc_constraint_new(sc_core.constants.CONSTR_3_f_a_a, command, sc_core.pm.SC_A_CONST, sc_core.pm.SC_N_CONST), True, 3) if button is None: raise RuntimeError("There are no button id for keyboard button command %s" % str(command)); button = button[2] button_id = -1 for i in keynodes.ui.keyboard.dictionary: if button.this == i.this: button_id = keynodes.ui.keyboard.dictionary[i] if button_id == -1: raise RuntimeError("Unknown keyboard button id for command %s" % str(command)) cmd = commands.KeyboardButton(button_id, 0.1, pressed) cmd.eventFinished = finish_callback cmds[cmd] = command cmd.start()
def checking(self, question): print "checking: Show map operation" # проверка входит ли вопрос в множество вопросов "поиск выходящих дуг" res = sc_utils.checkIncToSets(session,question,[sc_main_question],sc.SC_A_CONST|sc.SC_POS) if res is not None: return True else: return False
def addToSets(_session, _segment, _addr, _sets): """Create positive pair between each element of \p _sets list and \p _addr """ for _set in _sets: if not sc_utils.checkIncToSets( _session, _addr, [_set], sc.SC_A_CONST | sc.SC_POS | sc.SC_PERMANENT): sc_utils.createPairPosPerm(_session, _segment, _set, _addr, sc.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)
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 checkInputObjects(session, objects): """Check if objects contains sc_global_addr variable, which could became an instance of class SpaceObject @param session: current workable session @type session: sc_session @param objects: list of input objects which we are checking @type objects: list[sc_global_addr,..] @return: true if it's contains, false otherwise @rtype: bool """ starKey = space_keynodes.SpaceRelation.star planetKey = space_keynodes.SpaceRelation.planet result = False for object in objects: incl1 = sc_utils.checkIncToSets(session, object, [starKey], sc.SC_A_CONST | sc.SC_POS) incl2 = sc_utils.checkIncToSets(session, object, [planetKey], sc.SC_A_CONST | sc.SC_POS) if incl1 or incl2: result = True break return result
def build_node(_session, _el, _type): """Builds SCgNode based on sc-element """ # check if it isn't content node _cnt_type = sc_utils.getContentFormat(_session, _el) if _cnt_type is not None: obj = objects.ObjectSheet() obj.hideContent() obj._setScAddr(_el) # creating viewer try: logic = core.Kernel.getSingleton().createViewer(_cnt_type) obj.setLogic(logic) except exceptions.UnsupportedFormatError: core.Kernel.getSingleton().logManager.logWarning("Format %s not supported for viewing" % (_session.get_idtf(_cnt_type))) return obj else: type_name = "node/const/elem" # creating type name based on element type _const = getConstStr(_type) _stype = "elem" if sc_utils.checkIncToSets(_session, _el, [keynodes.info.stype_sheaf], sc.SC_A_CONST | sc.SC_POS | sc.SC_PERMANENT): _stype = "sheaf" elif sc_utils.checkIncToSets(_session, _el, [keynodes.info.stype_ext_obj_abstract], sc.SC_A_CONST | sc.SC_POS | sc.SC_PERMANENT): _stype = "abstract" elif sc_utils.checkIncToSets(_session, _el, [keynodes.info.stype_bin_orient_norole_rel], sc.SC_A_CONST | sc.SC_POS | sc.SC_PERMANENT): _stype = "binary" elif sc_utils.checkIncToSets(_session, _el, [keynodes.info.stype_ext_obj_real], sc.SC_A_CONST | sc.SC_POS | sc.SC_PERMANENT): _stype = "real" elif sc_utils.checkIncToSets(_session, _el, [keynodes.info.stype_bin_orient_role_rel], sc.SC_A_CONST | sc.SC_POS | sc.SC_PERMANENT): _stype = "role" elif sc_utils.checkIncToSets(_session, _el, [keynodes.info.stype_struct], sc.SC_A_CONST | sc.SC_POS | sc.SC_PERMANENT): _stype = "struct" elif sc_utils.checkIncToSets(_session, _el, [keynodes.info.stype_concept_norel], sc.SC_A_CONST | sc.SC_POS | sc.SC_PERMANENT): _stype = "term" if _const is not None: type_name = "node/%s/%s" % (_const, _stype) else: type_name = "node/elem" obj = scg_alphabet.createSCgNode(type_name) obj._setScAddr(_el) return obj return None
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 translateChildPoints(_session, _segment, _object): """Translate points, that lies on \p _object """ assert isinstance(_object, geom_objects.GeometryAbstractObject) obj_addr = _object._getScAddr() assert obj_addr is not None for _point, _pos in _object.getPoints(): pt_addr = _point._getScAddr() assert pt_addr is not None if not sc_utils.checkIncToSets(_session, pt_addr, [obj_addr], sc.SC_A_CONST | sc.SC_POS | sc.SC_PERMANENT): sc_utils.createPairPosPerm(_session, _segment, obj_addr, pt_addr, sc.SC_CONST)
def _checkAtom(self): """Checks if menu item is atom menu class """ session = core.Kernel.session() if sc_utils.checkIncToSets(session, self._getScAddr(), [keynodes.ui.atom_command], sc.SC_CONST): self.atom = True self._skin = "MenuTop_ButtonAtom" self._color = "#ffffff" # check if it is a question command if sc_utils.checkIncToSets(session, self._getScAddr(), [keynodes.ui.question_command], sc.SC_CONST): self.question = True self._skin = "MenuTop_ButtonQuestion" self._color = "#ffffff" return elif sc_utils.checkIncToSets(session, self._getScAddr(), [keynodes.ui.noatom_command], sc.SC_CONST): self.atom = False self._skin = "MenuTop_ButtonNoAtom" self._color = "#ffffff" return else: #object self.atom = False self.question = False self._skin = "MenuTop_ButtonObject" self._color = "#ffffff" return global logManager logManager.logWarning("Unknown atom class for a menu item '%s'" % self.getCaption())
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 translateChildPoints(_session, _segment, _object): """Translate points, that lies on \p _object """ assert isinstance(_object, geom_objects.GeometryAbstractObject) obj_addr = _object._getScAddr() assert obj_addr is not None for _point, _pos in _object.getPoints(): pt_addr = _point._getScAddr() assert pt_addr is not None if not sc_utils.checkIncToSets( _session, pt_addr, [obj_addr], sc.SC_A_CONST | sc.SC_POS | sc.SC_PERMANENT): sc_utils.createPairPosPerm(_session, _segment, obj_addr, pt_addr, sc.SC_CONST)
def translete_congr(_segment, _obj1, _obj2): # check if it have relation session = core.Kernel.session() res = sc_utils.searchPairsBinaryNoOrient(session, _obj1._getScAddr(), _obj2._getScAddr(), sc.SC_CONST) if res is not None: for result in res: if sc_utils.checkIncToSets(session, result[2], [geom_keynodes.Relation.nrel_congr], sc.SC_A_CONST | sc.SC_POS | sc.SC_PERMANENT): return # create new relation a = sc_utils.createPairBinaryNoOrient(session, _segment, _obj1._getScAddr(), _obj2._getScAddr(), sc.SC_CONST) sc_utils.createPairPosPerm(session, _segment, geom_keynodes.Relation.nrel_congr, a, sc.SC_CONST) return
def findCentralStar(session, planets): """ Finds parent planet. Another planets turn around it. @param session: current workable session @type session: sc_session @param planets: all planets @type planets: list[sc_global_addr] @return: parent planet @rtype: sc_global_addr """ parent = None star = space_keynodes.SpaceRelation.star for planet in planets: isStar = sc_utils.checkIncToSets(session, planet, [star], sc.SC_A_CONST) if isStar: parent = planet return parent
def generate_graph(_params, _segment): kernel = core.Kernel.getSingleton() session = kernel.session() segment = kernel.segment() # check type command = session.search_one_shot(session.sc_constraint_new(sc_constants.CONSTR_5_f_a_a_a_f, keynodes.ui.init_user_cmd, sc.SC_A_CONST, sc.SC_N_CONST, sc.SC_A_CONST, _params), True, 5) assert command is not None command = command[2] G = None # run one of generators global graph_generators for keynode, generator in graph_generators: # check type if not sc_utils.checkIncToSets(session, command, [keynode], sc.SC_CONST): continue G = generator() if G is None: return # create graph randomly g = Graph(segment, None, G) res = g.makeScGraph() # get current window output = kernel.getRootSheet() assert output is not None # make output set, that include whole graph construction kernel.translateFromSc(res, output._getScAddr())
def generate_graph(_params, _segment): kernel = core.Kernel.getSingleton() session = kernel.session() segment = kernel.segment() # check type command = session.search_one_shot( session.sc_constraint_new(sc_constants.CONSTR_5_f_a_a_a_f, keynodes.ui.init_user_cmd, sc.SC_A_CONST, sc.SC_N_CONST, sc.SC_A_CONST, _params), True, 5) assert command is not None command = command[2] G = None # run one of generators global graph_generators for keynode, generator in graph_generators: # check type if not sc_utils.checkIncToSets(session, command, [keynode], sc.SC_CONST): continue G = generator() if G is None: return # create graph randomly g = Graph(segment, None, G) res = g.makeScGraph() # get current window output = kernel.getRootSheet() assert output is not None # make output set, that include whole graph construction kernel.translateFromSc(res, output._getScAddr())
def translate_impl(self, _input, _output): """Translator implementation @param _input: input data set @type _input: sc_global_addr @param _output: output window (must be created) @type _output: sc_global_addr @return: list of errors each element of list is a tuple(object, error) @rtype: list """ #look for question node els = session.search11_f_a_a_a_a_a_f_a_f_a_f(_input, sc.SC_A_CONST|sc.SC_POS, sc.SC_N_CONST, sc.SC_A_CONST|sc.SC_POS, sc.SC_N_CONST, sc.SC_A_CONST|sc.SC_POS, sc_keys.n_2, sc.SC_A_CONST|sc.SC_POS, sc_keys.n_1, sc.SC_A_CONST|sc.SC_POS, sc_keys.info.stype_sheaf) el = sc_utils.searchOneShot(els) assert el is not None #get question node question_node = el[4] #check if answer on question can be translated if sc_utils.checkIncToSets(session, question_node, [sc_show_map_question_set], sc.SC_POS | sc.SC_CONST): print "Show map question, translating answer" #parse sc-construction parser = SCParser() parser.parse(_input, question_node) data = parser.toYmapsML() file_name = self._generate_filename() self._send_data_to_server(file_name, data) #set returned script to _output node content session.set_content_str(_output, env.server_address + "/file/"+file_name) errors = [] print "sc2yandexmaps finish translation" return errors
def _updateView(self): if self.needLocalizationUpdate: session = self.kernel.session() _caption = "#aaaaaaunknown" # get question class it = session.create_iterator(session.sc_constraint_new(sc_core.constants.CONSTR_3_a_a_f, sc_core.pm.SC_N_CONST, sc_core.pm.SC_A_CONST | sc_core.pm.SC_POS, self._getScAddr()), True) while not it.is_over(): _class = it.value(0) if sc_utils.checkIncToSets(session, _class, [keynodes.questions._class], sc_core.pm.SC_CONST): _caption = sc_utils.getLocalizedIdentifier(core.Kernel.session(), _class)[0] if len(_caption) == 0: _caption = "#aaaaaaunknown" break it.next() self.setText(_caption) self.needLocalizationUpdate = False objects.ObjectOverlay._updateView(self)
def translete_congr(_segment, _obj1, _obj2): # check if it have relation session = core.Kernel.session() res = sc_utils.searchPairsBinaryNoOrient(session, _obj1._getScAddr(), _obj2._getScAddr(), sc.SC_CONST) if res is not None: for result in res: if sc_utils.checkIncToSets( session, result[2], [geom_keynodes.Relation.nrel_congr], sc.SC_A_CONST | sc.SC_POS | sc.SC_PERMANENT): return # create new relation a = sc_utils.createPairBinaryNoOrient(session, _segment, _obj1._getScAddr(), _obj2._getScAddr(), sc.SC_CONST) sc_utils.createPairPosPerm(session, _segment, geom_keynodes.Relation.nrel_congr, a, sc.SC_CONST) return
def init_cmd(session, segment, sheet, _menu_item_addr, _general_formul, _cmd_class_set, _init_set): """Initialize question/command from template @param session: Session to work with sc-memory @param segment: Segment to create sc-constructions @param sheet: Current root sheet (command initiated from it) @param _menu_item_addr: sc-element that designate command (question) menu item @type _menu_item_addr: sc_addr @param _general_formul: sc-element that designate general formulation relation (different for questions and commands) @type _general_formul: sc_addr @param _cmd_class_set: sc-element that designate class of commands (used to search command node in template) @type _cmd_class_set: sc_addr @param _init_set: sc-element that designate initiated commands set (different for commands and questions) @type _init_set: sc_addr """ kernel = core.Kernel.getSingleton() # getting question template q_templ = sc_utils.searchOneShotBinPairAttrToNode(session, _menu_item_addr, _general_formul, sc.SC_CONST) if not q_templ: raise RuntimeWarning("Question '%s' haven't template" % _caption) return # getting question node it = session.create_iterator( session.sc_constraint_new(sc_constants.CONSTR_5_f_a_a_a_f, _cmd_class_set, sc.SC_ARC, sc.SC_NODE, sc.SC_ARC, q_templ), True) question_node = None while not it.is_over(): if sc_utils.checkIncToSets(session, it.value(2), [q_templ], 0): question_node = it.value(2) break it.next() if question_node is None: raise RuntimeError( "Can't get command (question) node for a '%s' command" % str(_menu_item_addr)) # creating question using template: # * iterate through elements of template set # * making values of parameters cmd_desc_..., add that values to addit_elements map # * replace var elements to const elements # * replace meta elements to var elements # * link replaced arcs params = {} addit_elements = { } # additional elements we need to add into question after params setup elements = [] pairs = [] it = session.create_iterator( session.sc_constraint_new( sc_constants.CONSTR_3_f_a_a, q_templ, sc.SC_A_CONST | sc.SC_POS, # | sc.SC_PERMANENT, 0), True) while not it.is_over(): _el = it.value(2) elements.append(_el) # selected elements if _el.this == keynodes.ui.arg_set.this: params[str(_el.this)], elms = get_arguments_set(session, segment) addit_elements[str(_el.this)] = elms elif _el.this == keynodes.ui.arg_set_only.this: # place just set node into question node params[str(_el.this)], elms = get_arguments_set(session, segment) elif _el.this == keynodes.ui.arg_cur_window.this: params[str(_el.this)] = sheet elif _el.this == keynodes.ui.arg_1.this: arguments = core.Kernel.getSingleton().getArguments() if len(arguments) > 0: params[str(_el.this)] = arguments[0]._getScAddr() elif _el.this == keynodes.ui.arg_2.this: arguments = core.Kernel.getSingleton().getArguments() if len(arguments) > 1: params[str(_el.this)] = arguments[1]._getScAddr() # elif _el.this == keynodes.ui.cmd_desc_curr_window.this: # params[str(_el.this)] = kernel.rootSheet._getScAddr() else: el_type = session.get_type(_el) idtf = session.get_idtf(_el) if not sc_utils.isSystemId(idtf) or (el_type & sc.SC_CONST): params[str(_el.this)] = _el else: # recreate var and meta elements using rules: # * var -> const # * meta -> var post_type = 0 if el_type & sc.SC_VAR: post_type = sc.SC_CONST elif el_type & sc.SC_META: post_type = sc.SC_VAR else: raise RuntimeWarning( "Unknown const type for element '%s'" % str(_el)) if el_type & sc.SC_ARC: pairs.append(_el) params[str(_el.this)] = session.create_el( segment, sc.SC_ARC | post_type) elif el_type & sc.SC_NODE: params[str(_el.this)] = session.create_el( segment, sc.SC_NODE | post_type) # TODO: copy structure types for elements it.next() # add selected set to question set q_node_new = params[str(question_node.this)] if sc_utils.checkIncToSets( session, keynodes.ui.arg_set, [question_node], sc.SC_POS | sc.SC_VAR) and sc_utils.checkIncToSets( session, keynodes.ui.arg_set, [q_templ], sc.SC_POS | sc.SC_CONST): # make pairs to additional elements for el in addit_elements[str(keynodes.ui.arg_set.this)]: assert sc_utils.createPairPosPerm(session, segment, q_node_new, el, sc.SC_CONST) # linking arcs for pair in pairs: # get begin and end elements _beg = session.get_beg(pair) _end = session.get_end(pair) if params.has_key(str(_beg.this)): _beg = params[str(_beg.this)] if params.has_key(str(_end.this)): _end = params[str(_end.this)] pair_new = params[str(pair.this)] session.set_beg(pair_new, _beg) session.set_end(pair_new, _end) # make authors set authors_node = sc_utils.createNodeElement(session, segment, sc.SC_CONST) sc_utils.createPairPosPerm(session, segment, authors_node, core.Kernel.getSingleton().getUserAddr(), sc.SC_CONST) assert authors_node is not None authors_pair_sheaf = sc_utils.createPairBinaryOrient( session, segment, params[str(question_node.this)], authors_node, sc.SC_CONST) assert authors_pair_sheaf is not None assert sc_utils.createPairPosPerm(session, segment, keynodes.common.nrel_authors, authors_pair_sheaf, sc.SC_CONST) # make output windows set output_node = sc_utils.createNodeElement(session, segment, sc.SC_CONST) assert output_node is not None # sc_utils.copySet(session, keynodes.ui.set_output_windows, output_node, segment) output_count = 0 it = session.create_iterator( session.sc_constraint_new(sc_constants.CONSTR_3_f_a_a, keynodes.ui.set_output_windows, sc.SC_ARC, 0), True) while not it.is_over(): sc_utils.createPair(session, segment, output_node, it.value(2), session.get_type(it.value(1))) output_count += 1 it.next() if output_count == 0: sc_utils.createPairPosPerm(session, segment, output_node, kernel.getMainWindow()._getScAddr(), sc.SC_CONST) # link output windows set to question output_sheaf = sc_utils.createPairBinaryOrient( session, segment, output_node, params[str(question_node.this)], sc.SC_CONST) assert output_sheaf is not None sc_utils.createPairPosPerm(session, segment, keynodes.ui.nrel_set_of_output_windows, output_sheaf, sc.SC_CONST) # initiate question assert sc_utils.createPairPosPerm(session, segment, _init_set, params[str(question_node.this)], sc.SC_CONST) is not None
def find_graph(_params, _segment): kernel = core.Kernel.getSingleton() session = kernel.session() segment = kernel.segment() # check type question = session.search_one_shot(session.sc_constraint_new(sc_constants.CONSTR_5_f_a_a_a_f, keynodes.questions.initiated, sc.SC_A_CONST, sc.SC_N_CONST, sc.SC_A_CONST, _params), True, 5) assert question is not None question = question[2] # check command type if sc_utils.checkIncToSets(session, question, [graph_keynodes.Command.search_graph_full], sc.SC_CONST): graph = session.search_one_shot(session.sc_constraint_new(sc_constants.CONSTR_3_f_a_a, question, sc.SC_A_CONST, sc.SC_N_CONST), True, 5) if graph is None: return struct = sc_utils.createNodeElement(session, segment, sc.SC_CONST) graph = graph[2] sc_utils.createPairPosPerm(session, segment, struct, graph, sc.SC_CONST) sc_utils.createPairPosPerm(session, segment, struct, graph_keynodes.Common.rrel_edge, sc.SC_CONST) sc_utils.createPairPosPerm(session, segment, struct, graph_keynodes.Common.rrel_vertex, sc.SC_CONST) # collect verticies it = session.create_iterator(session.sc_constraint_new(sc_constants.CONSTR_5_f_a_a_a_f, graph, sc.SC_A_CONST | sc.SC_POS, sc.SC_NODE, sc.SC_A_CONST | sc.SC_POS, graph_keynodes.Common.rrel_vertex), True) while not it.is_over(): for i in xrange(1, 4): sc_utils.createPairPosPerm(session, segment, struct, it.value(i), sc.SC_CONST) it.next() it = session.create_iterator(session.sc_constraint_new(sc_constants.CONSTR_5_f_a_a_a_f, graph, sc.SC_A_CONST | sc.SC_POS, sc.SC_NODE, sc.SC_A_CONST | sc.SC_POS, graph_keynodes.Common.rrel_edge), True) # collect edges while not it.is_over(): for i in xrange(1, 4): sc_utils.createPairPosPerm(session, segment, struct, it.value(i), sc.SC_CONST) it1 = session.create_iterator(session.sc_constraint_new(sc_constants.CONSTR_3_f_a_a, it.value(2), sc.SC_A_CONST | sc.SC_POS, sc.SC_NODE), True) while not it1.is_over(): sc_utils.createPairPosPerm(session, segment, struct, it1.value(1), sc.SC_CONST) it1.next() it.next() sc_utils.makeAnswer(session, segment, question, struct)
def addToSets(_session, _segment, _addr, _sets): """Create positive pair between each element of \p _sets list and \p _addr """ for _set in _sets: if not sc_utils.checkIncToSets(_session, _addr, [_set], sc.SC_A_CONST | sc.SC_POS | sc.SC_PERMANENT): sc_utils.createPairPosPerm(_session, _segment, _set, _addr, sc.SC_CONST)
def user_output_answer(_params, _segment): # trying to find question node session = core.Kernel.session() # getting answer sheaf node answer_sheaf = session.search_one_shot(session.sc_constraint_new(sc_core.constants.CONSTR_5_f_a_a_a_f, keynodes.questions.nrel_answer, sc_core.pm.SC_A_CONST, sc_core.pm.SC_N_CONST, sc_core.pm.SC_A_CONST, _params), True, 5) if answer_sheaf is None: raise Exception("Can't find answer sheaf node") answer_sheaf = answer_sheaf[2] # go to begin of pair question_node = session.search_one_shot(session.sc_constraint_new(sc_core.constants.CONSTR_5_f_a_a_a_f, answer_sheaf, sc_core.pm.SC_A_CONST, sc_core.pm.SC_N_CONST, sc_core.pm.SC_A_CONST, keynodes.n_1), True, 5) if question_node is None: raise Exception("Can't find question node") question_node = question_node[2] if question_node is None: return # get author and check if it's a user authors_set = sc_utils.searchOneShotBinPairAttrFromNode(session, question_node, keynodes.common.nrel_authors, sc_core.pm.SC_CONST) if authors_set is None: return is_user = False it = session.create_iterator(session.sc_constraint_new(sc_core.constants.CONSTR_3_f_a_a, authors_set, sc_core.pm.SC_A_CONST | sc_core.pm.SC_POS, sc_core.pm.SC_N_CONST), True) while not it.is_over(): author = it.value(2) if sc_utils.checkIncToSets(session, author, [keynodes.ui.user], sc_core.pm.SC_CONST): is_user = True it.next() if not is_user: return # get answer node answer_node = session.search_one_shot(session.sc_constraint_new(sc_core.constants.CONSTR_5_f_a_a_a_f, answer_sheaf, sc_core.pm.SC_A_CONST, sc_core.pm.SC_N_CONST, sc_core.pm.SC_A_CONST, keynodes.n_2), True, 5) if answer_node is None: return answer_node = answer_node[2] # get output windows output_set = sc_utils.searchOneShotBinPairAttrToNode(session, question_node, keynodes.ui.nrel_set_of_output_windows, sc_core.pm.SC_CONST) if output_set is None: return it = session.create_iterator(session.sc_constraint_new(sc_core.constants.CONSTR_3_f_a_a, output_set, sc_core.pm.SC_A_CONST | sc_core.pm.SC_POS, sc_core.pm.SC_N_CONST), True) while not it.is_over(): try: core.Kernel.getSingleton().translateFromSc(answer_node, it.value(2)) except: import sys, traceback print "Error:", sys.exc_info()[0] traceback.print_exc(file=sys.stdout) it.next()
def find_graph(_params, _segment): kernel = core.Kernel.getSingleton() session = kernel.session() segment = kernel.segment() # check type question = session.search_one_shot( session.sc_constraint_new(sc_constants.CONSTR_5_f_a_a_a_f, keynodes.questions.initiated, sc.SC_A_CONST, sc.SC_N_CONST, sc.SC_A_CONST, _params), True, 5) assert question is not None question = question[2] # check command type if sc_utils.checkIncToSets(session, question, [graph_keynodes.Command.search_graph_full], sc.SC_CONST): graph = session.search_one_shot( session.sc_constraint_new(sc_constants.CONSTR_3_f_a_a, question, sc.SC_A_CONST, sc.SC_N_CONST), True, 5) if graph is None: return struct = sc_utils.createNodeElement(session, segment, sc.SC_CONST) graph = graph[2] sc_utils.createPairPosPerm(session, segment, struct, graph, sc.SC_CONST) sc_utils.createPairPosPerm(session, segment, struct, graph_keynodes.Common.rrel_edge, sc.SC_CONST) sc_utils.createPairPosPerm(session, segment, struct, graph_keynodes.Common.rrel_vertex, sc.SC_CONST) # collect verticies it = session.create_iterator( session.sc_constraint_new(sc_constants.CONSTR_5_f_a_a_a_f, graph, sc.SC_A_CONST | sc.SC_POS, sc.SC_NODE, sc.SC_A_CONST | sc.SC_POS, graph_keynodes.Common.rrel_vertex), True) while not it.is_over(): for i in xrange(1, 4): sc_utils.createPairPosPerm(session, segment, struct, it.value(i), sc.SC_CONST) it.next() it = session.create_iterator( session.sc_constraint_new(sc_constants.CONSTR_5_f_a_a_a_f, graph, sc.SC_A_CONST | sc.SC_POS, sc.SC_NODE, sc.SC_A_CONST | sc.SC_POS, graph_keynodes.Common.rrel_edge), True) # collect edges while not it.is_over(): for i in xrange(1, 4): sc_utils.createPairPosPerm(session, segment, struct, it.value(i), sc.SC_CONST) it1 = session.create_iterator( session.sc_constraint_new(sc_constants.CONSTR_3_f_a_a, it.value(2), sc.SC_A_CONST | sc.SC_POS, sc.SC_NODE), True) while not it1.is_over(): sc_utils.createPairPosPerm(session, segment, struct, it1.value(1), sc.SC_CONST) it1.next() it.next() sc_utils.makeAnswer(session, segment, question, struct)
def user_output_answer(_params, _segment): # trying to find question node session = core.Kernel.session() # getting answer sheaf node answer_sheaf = session.search_one_shot( session.sc_constraint_new(sc_core.constants.CONSTR_5_f_a_a_a_f, keynodes.questions.nrel_answer, sc_core.pm.SC_A_CONST, sc_core.pm.SC_N_CONST, sc_core.pm.SC_A_CONST, _params), True, 5) if answer_sheaf is None: raise Exception("Can't find answer sheaf node") answer_sheaf = answer_sheaf[2] # go to begin of pair question_node = session.search_one_shot( session.sc_constraint_new(sc_core.constants.CONSTR_5_f_a_a_a_f, answer_sheaf, sc_core.pm.SC_A_CONST, sc_core.pm.SC_N_CONST, sc_core.pm.SC_A_CONST, keynodes.n_1), True, 5) if question_node is None: raise Exception("Can't find question node") question_node = question_node[2] if question_node is None: return # get author and check if it's a user authors_set = sc_utils.searchOneShotBinPairAttrFromNode( session, question_node, keynodes.common.nrel_authors, sc_core.pm.SC_CONST) if authors_set is None: return is_user = False it = session.create_iterator( session.sc_constraint_new(sc_core.constants.CONSTR_3_f_a_a, authors_set, sc_core.pm.SC_A_CONST | sc_core.pm.SC_POS, sc_core.pm.SC_N_CONST), True) while not it.is_over(): author = it.value(2) if sc_utils.checkIncToSets(session, author, [keynodes.ui.user], sc_core.pm.SC_CONST): is_user = True it.next() if not is_user: return # get answer node answer_node = session.search_one_shot( session.sc_constraint_new(sc_core.constants.CONSTR_5_f_a_a_a_f, answer_sheaf, sc_core.pm.SC_A_CONST, sc_core.pm.SC_N_CONST, sc_core.pm.SC_A_CONST, keynodes.n_2), True, 5) if answer_node is None: return answer_node = answer_node[2] # get output windows output_set = sc_utils.searchOneShotBinPairAttrToNode( session, question_node, keynodes.ui.nrel_set_of_output_windows, sc_core.pm.SC_CONST) if output_set is None: return it = session.create_iterator( session.sc_constraint_new(sc_core.constants.CONSTR_3_f_a_a, output_set, sc_core.pm.SC_A_CONST | sc_core.pm.SC_POS, sc_core.pm.SC_N_CONST), True) while not it.is_over(): try: core.Kernel.getSingleton().translateFromSc(answer_node, it.value(2)) except: import sys, traceback print "Error:", sys.exc_info()[0] traceback.print_exc(file=sys.stdout) it.next()
def calculate_graph_element_prop(_params, _segment): kernel = core.Kernel.getSingleton() session = kernel.session() segment = kernel.segment() # check type question = session.search_one_shot(session.sc_constraint_new(sc_constants.CONSTR_5_f_a_a_a_f, keynodes.questions.initiated, sc.SC_A_CONST, sc.SC_N_CONST, sc.SC_A_CONST, _params), True, 5) assert question is not None question = question[2] global graph_prop_calculators for question_type, calculator, relation in graph_element_prop_calculators: # check command type if sc_utils.checkIncToSets(session, question, [question_type], sc.SC_CONST): element = session.search_one_shot(session.sc_constraint_new(sc_constants.CONSTR_3_f_a_a, question, sc.SC_A_CONST, sc.SC_N_CONST), True, 3) if element is None: return element = element[2] graph = None arc = None it = session.create_iterator(session.sc_constraint_new(sc_constants.CONSTR_3_a_a_f, sc.SC_NODE, sc.SC_A_CONST | sc.SC_POS, element), True) while not it.is_over(): if sc_utils.checkIncToSets(session, it.value(0), [graph_keynodes.Common.graph], sc.SC_CONST): graph = it.value(0) arc = it.value(1) break it.next() if graph is None: continue # make graph and calculate property value g = Graph(segment, graph) sc2obj = g.makeNxGraph() result = calculator(g.graphNx, sc2obj[str(element.this)]) # if result is None: raise RuntimeWarning("Calculator can't calculate value") value = sc_utils.createNodeElement(session, segment, sc.SC_CONST) bin_rel = sc_utils.createPairBinaryOrientFull(session, segment, arc, value, sc.SC_CONST) a = sc_utils.createPairPosPerm(session, segment, relation, bin_rel[0], sc.SC_CONST) elements = translate_value(session, segment, value, result) elements.extend([value, graph, a, relation]) elements.extend(bin_rel) answer = sc_utils.createNodeElement(session, segment, sc.SC_CONST) for el in elements: sc_utils.createPairPosPerm(session, segment, answer, el, sc.SC_CONST) sc_utils.makeAnswer(session, segment, question, answer)
def getFormatIcon(self, _format): """Return icon associated with specified format @param _format: sc-node that designate format @type _format: sc_addr @return: Name of texture that contains icon associated to _format, if there are no any icons, then return None """ import suit.core.sc_utils as sc_utils import sc_core.constants as sc_constants import sc_core.pm as sc import ogre.renderer.OGRE as ogre session = core.Kernel.session() icon = None idtf_set = sc_utils.searchOneShotBinPairAttrToNode( session, _format, keynodes.common.nrel_identification, sc.SC_CONST) if idtf_set is not None: it1 = session.create_iterator( session.sc_constraint_new(sc_constants.CONSTR_3_f_a_a, idtf_set, sc.SC_A_CONST, sc.SC_N_CONST), True) while not it1.is_over(): if sc_utils.checkIncToSets(session, it1.value(2), [keynodes.common.group_image], sc.SC_CONST): icon = it1.value(2) break it1.next() if icon is None: return None _fmt = sc_utils.getContentFormat(session, icon) assert _fmt is not None _cont = session.get_content_const(icon) assert _cont is not None _cont_data = _cont.convertToCont() data = _cont.get_data(_cont_data.d.size) stream = ogre.MemoryDataStream("%s" % str(self), _cont_data.d.size, False) stream.setData(data) try: img = ogre.Image() img.load(stream, ogre.Image.getFileExtFromMagic(stream)) except: import sys, traceback print "Error:", sys.exc_info()[0] traceback.print_exc(file=sys.stdout) icon_name = "icon_%s" % str(_format) ogre.TextureManager.getSingleton().loadImage( icon_name, "General", img) return icon_name return None
def translate_impl(self, _input, _output): """Translator implementation @param _input: input data set @type _input: sc_global_addr @param _output: output window (must be created) @type _output: sc_global_addr @return: list of errors each element of list is a tuple(object, error) @rtype: list """ errors = [] # FIXME: think about multiply windows for one sc-element objs = objects.ScObject._sc2Objects(_output) assert len(objs) > 0 sheet = objs[0] assert type(sheet) is objects.ObjectSheet session = core.Kernel.session() # remove old graph while len(sheet.getChilds()) > 0: sheet._deleteObject(sheet.getChilds()[0]) # trying to fin graph node # graph = session.search_one_shot(session.sc_constraint_new(sc_constants.CONSTR_5_f_a_a_a_f, # graph_keynodes.Common.graph, # sc.SC_A_CONST, # sc.SC_N_CONST, # sc.SC_A_CONST, # _input), True, 5) it = session.create_iterator(session.sc_constraint_new(sc_constants.CONSTR_3_f_a_a, _input, sc.SC_A_CONST | sc.SC_POS, sc.SC_NODE), True) graph = None while not it.is_over(): if sc_utils.checkIncToSets(session, it.value(2), [graph_keynodes.Common.graph], sc.SC_CONST): graph = it.value(2) break it.next() if graph is not None: # get all nodes and translate them it = session.create_iterator(session.sc_constraint_new(sc_constants.CONSTR_5_f_a_a_a_f, graph, sc.SC_A_CONST | sc.SC_POS, sc.SC_NODE, sc.SC_A_CONST | sc.SC_POS, graph_keynodes.Common.rrel_vertex), True) sc2Obj = {} while not it.is_over(): sc_node = it.value(2) if sc_utils.checkIncToSets(session, sc_node, [_input], sc.SC_CONST | sc.SC_POS): sc2Obj[str(sc_node.this)] = translate_node(session, sc_node) it.next() # get all edges and translate them it = session.create_iterator(session.sc_constraint_new(sc_constants.CONSTR_5_f_a_a_a_f, graph, sc.SC_A_CONST | sc.SC_POS, sc.SC_NODE, sc.SC_A_CONST | sc.SC_POS, graph_keynodes.Common.rrel_edge), True) while not it.is_over(): sc_edge = it.value(2) if sc_utils.checkIncToSets(session, sc_edge, [_input], sc.SC_CONST | sc.SC_POS): sc2Obj[str(sc_edge.this)] = translate_edge(session, sc_edge, sc2Obj) it.next() for obj in sc2Obj.values(): obj.setWasInMemory(True) sheet.addChild(obj) else: errors.append("There are no graph structure to translate") return errors
def init_cmd(session, segment, sheet, _menu_item_addr, _general_formul, _cmd_class_set, _init_set): """Initialize question/command from template @param session: Session to work with sc-memory @param segment: Segment to create sc-constructions @param sheet: Current root sheet (command initiated from it) @param _menu_item_addr: sc-element that designate command (question) menu item @type _menu_item_addr: sc_addr @param _general_formul: sc-element that designate general formulation relation (different for questions and commands) @type _general_formul: sc_addr @param _cmd_class_set: sc-element that designate class of commands (used to search command node in template) @type _cmd_class_set: sc_addr @param _init_set: sc-element that designate initiated commands set (different for commands and questions) @type _init_set: sc_addr """ kernel = core.Kernel.getSingleton() # getting question template q_templ = sc_utils.searchOneShotBinPairAttrToNode(session, _menu_item_addr, _general_formul, sc.SC_CONST) if not q_templ: raise RuntimeWarning("Question '%s' haven't template" % _caption) return # getting question node it = session.create_iterator(session.sc_constraint_new(sc_constants.CONSTR_5_f_a_a_a_f, _cmd_class_set, sc.SC_ARC, sc.SC_NODE, sc.SC_ARC, q_templ), True) question_node = None while not it.is_over(): if sc_utils.checkIncToSets(session, it.value(2), [q_templ], 0): question_node = it.value(2) break it.next() if question_node is None: raise RuntimeError("Can't get command (question) node for a '%s' command" % str(_menu_item_addr)) # creating question using template: # * iterate through elements of template set # * making values of parameters cmd_desc_..., add that values to addit_elements map # * replace var elements to const elements # * replace meta elements to var elements # * link replaced arcs params = {} addit_elements = {} # additional elements we need to add into question after params setup elements = [] pairs = [] it = session.create_iterator(session.sc_constraint_new(sc_constants.CONSTR_3_f_a_a, q_templ, sc.SC_A_CONST | sc.SC_POS,# | sc.SC_PERMANENT, 0), True) while not it.is_over(): _el = it.value(2) elements.append(_el) # selected elements if _el.this == keynodes.ui.arg_set.this: params[str(_el.this)], elms = get_arguments_set(session, segment) addit_elements[str(_el.this)] = elms elif _el.this == keynodes.ui.arg_set_only.this: # place just set node into question node params[str(_el.this)], elms = get_arguments_set(session, segment) elif _el.this == keynodes.ui.arg_all_el.this: params[str(_el.this)], elms = get_all_elements_set(session, segment) elif _el.this == keynodes.ui.arg_cur_window.this: params[str(_el.this)] = sheet elif _el.this == keynodes.ui.arg_1.this: arguments = core.Kernel.getSingleton().getArguments() if len(arguments) > 0: params[str(_el.this)] = arguments[0]._getScAddr() elif _el.this == keynodes.ui.arg_2.this: arguments = core.Kernel.getSingleton().getArguments() if len(arguments) > 1: params[str(_el.this)] = arguments[1]._getScAddr() elif _el.this == keynodes.ui.arg_3.this: arguments = core.Kernel.getSingleton().getArguments() if len(arguments) > 1: params[str(_el.this)] = arguments[2]._getScAddr() # elif _el.this == keynodes.ui.cmd_desc_curr_window.this: # params[str(_el.this)] = kernel.rootSheet._getScAddr() else: el_type = session.get_type(_el) idtf = session.get_idtf(_el) if not sc_utils.isSystemId(idtf) or (el_type & sc.SC_CONST): params[str(_el.this)] = _el else: # recreate var and meta elements using rules: # * var -> const # * meta -> var post_type = 0 if el_type & sc.SC_VAR: post_type = sc.SC_CONST elif el_type & sc.SC_META: post_type = sc.SC_VAR else: raise RuntimeWarning("Unknown const type for element '%s'" % str(_el)) if el_type & sc.SC_ARC: pairs.append(_el) params[str(_el.this)] = session.create_el(segment, sc.SC_ARC | post_type) elif el_type & sc.SC_NODE: params[str(_el.this)] = session.create_el(segment, sc.SC_NODE | post_type) # TODO: copy structure types for elements it.next() # add selected set to question set q_node_new = params[str(question_node.this)] if sc_utils.checkIncToSets(session, keynodes.ui.arg_set, [question_node], sc.SC_POS | sc.SC_VAR) and sc_utils.checkIncToSets(session, keynodes.ui.arg_set, [q_templ], sc.SC_POS | sc.SC_CONST): # make pairs to additional elements for el in addit_elements[str(keynodes.ui.arg_set.this)]: assert sc_utils.createPairPosPerm(session, segment, q_node_new, el, sc.SC_CONST) # linking arcs for pair in pairs: # get begin and end elements _beg = session.get_beg(pair) _end = session.get_end(pair) if params.has_key(str(_beg.this)): _beg = params[str(_beg.this)] if params.has_key(str(_end.this)): _end = params[str(_end.this)] pair_new = params[str(pair.this)] session.set_beg(pair_new, _beg) session.set_end(pair_new, _end) # make authors set authors_node = sc_utils.createNodeElement(session, segment, sc.SC_CONST) sc_utils.createPairPosPerm(session, segment, authors_node, core.Kernel.getSingleton().getUserAddr(), sc.SC_CONST) assert authors_node is not None authors_pair_sheaf = sc_utils.createPairBinaryOrient(session, segment, params[str(question_node.this)], authors_node, sc.SC_CONST) assert authors_pair_sheaf is not None assert sc_utils.createPairPosPerm(session, segment, keynodes.common.nrel_authors, authors_pair_sheaf, sc.SC_CONST) # make output windows set output_node = sc_utils.createNodeElement(session, segment, sc.SC_CONST) assert output_node is not None # sc_utils.copySet(session, keynodes.ui.set_output_windows, output_node, segment) output_count = 0 it = session.create_iterator(session.sc_constraint_new(sc_constants.CONSTR_3_f_a_a, keynodes.ui.set_output_windows, sc.SC_ARC, 0), True) while not it.is_over(): sc_utils.createPair(session, segment, output_node, it.value(2), session.get_type(it.value(1))) output_count += 1 it.next() if output_count == 0: sc_utils.createPairPosPerm(session, segment, output_node, kernel.getMainWindow()._getScAddr(), sc.SC_CONST ) # link output windows set to question output_sheaf = sc_utils.createPairBinaryOrient(session, segment, output_node, params[str(question_node.this)], sc.SC_CONST) assert output_sheaf is not None sc_utils.createPairPosPerm(session, segment, keynodes.ui.nrel_set_of_output_windows, output_sheaf, sc.SC_CONST) # initiate question assert sc_utils.createPairPosPerm(session, segment, _init_set, params[str(question_node.this)], sc.SC_CONST) is not None
def calculate_graph_prop(_params, _segment): kernel = core.Kernel.getSingleton() session = kernel.session() segment = kernel.segment() # check type question = session.search_one_shot( session.sc_constraint_new(sc_constants.CONSTR_5_f_a_a_a_f, keynodes.questions.initiated, sc.SC_A_CONST, sc.SC_N_CONST, sc.SC_A_CONST, _params), True, 5) assert question is not None question = question[2] global graph_prop_calculators for question_type, calculator, relation in graph_prop_calculators: # check command type if sc_utils.checkIncToSets(session, question, [question_type], sc.SC_CONST): graph = session.search_one_shot( session.sc_constraint_new(sc_constants.CONSTR_3_f_a_a, question, sc.SC_A_CONST, sc.SC_N_CONST), True, 3) if graph is None: return graph = graph[2] if not sc_utils.checkIncToSets(session, graph, [graph_keynodes.Common.graph], sc.SC_CONST): return g = Graph(segment, graph) g.makeNxGraph() result = calculator(g.graphNx) if result is None: raise RuntimeWarning("Calculator can't calculate value") value = sc_utils.createNodeElement(session, segment, sc.SC_CONST) bin_rel = sc_utils.createPairBinaryOrientFull( session, segment, graph, value, sc.SC_CONST) a = sc_utils.createPairPosPerm(session, segment, relation, bin_rel[0], sc.SC_CONST) elements = translate_value(session, segment, value, result) elements.extend([value, graph, a, relation]) elements.extend(bin_rel) answer = sc_utils.createNodeElement(session, segment, sc.SC_CONST) for el in elements: sc_utils.createPairPosPerm(session, segment, answer, el, sc.SC_CONST) sc_utils.makeAnswer(session, segment, question, answer)
def translate_impl(self, _input, _output): """Translator implementation @param _input: input data set @type _input: sc_global_addr @param _output: output window (must be created) @type _output: sc_global_addr @return: list of errors each element of list is a tuple(object, error) @rtype: list """ errors = [] # FIXME: think about multiply windows for one sc-element objs = objects.ScObject._sc2Objects(_output) assert len(objs) > 0 sheet = objs[0] assert type(sheet) is objects.ObjectSheet session = core.Kernel.session() # remove old graph while len(sheet.getChilds()) > 0: sheet._deleteObject(sheet.getChilds()[0]) # trying to fin graph node # graph = session.search_one_shot(session.sc_constraint_new(sc_constants.CONSTR_5_f_a_a_a_f, # graph_keynodes.Common.graph, # sc.SC_A_CONST, # sc.SC_N_CONST, # sc.SC_A_CONST, # _input), True, 5) it = session.create_iterator( session.sc_constraint_new(sc_constants.CONSTR_3_f_a_a, _input, sc.SC_A_CONST | sc.SC_POS, sc.SC_NODE), True) graph = None while not it.is_over(): if sc_utils.checkIncToSets(session, it.value(2), [graph_keynodes.Common.graph], sc.SC_CONST): graph = it.value(2) break it.next() if graph is not None: # get all nodes and translate them it = session.create_iterator( session.sc_constraint_new(sc_constants.CONSTR_5_f_a_a_a_f, graph, sc.SC_A_CONST | sc.SC_POS, sc.SC_NODE, sc.SC_A_CONST | sc.SC_POS, graph_keynodes.Common.rrel_vertex), True) sc2Obj = {} while not it.is_over(): sc_node = it.value(2) if sc_utils.checkIncToSets(session, sc_node, [_input], sc.SC_CONST | sc.SC_POS): sc2Obj[str(sc_node.this)] = translate_node( session, sc_node) it.next() # get all edges and translate them it = session.create_iterator( session.sc_constraint_new(sc_constants.CONSTR_5_f_a_a_a_f, graph, sc.SC_A_CONST | sc.SC_POS, sc.SC_NODE, sc.SC_A_CONST | sc.SC_POS, graph_keynodes.Common.rrel_edge), True) while not it.is_over(): sc_edge = it.value(2) if sc_utils.checkIncToSets(session, sc_edge, [_input], sc.SC_CONST | sc.SC_POS): sc2Obj[str(sc_edge.this)] = translate_edge( session, sc_edge, sc2Obj) it.next() for obj in sc2Obj.values(): obj.setWasInMemory(True) sheet.addChild(obj) else: errors.append("There are no graph structure to translate") return errors
def calculate_graph_element_prop(_params, _segment): kernel = core.Kernel.getSingleton() session = kernel.session() segment = kernel.segment() # check type question = session.search_one_shot( session.sc_constraint_new(sc_constants.CONSTR_5_f_a_a_a_f, keynodes.questions.initiated, sc.SC_A_CONST, sc.SC_N_CONST, sc.SC_A_CONST, _params), True, 5) assert question is not None question = question[2] global graph_prop_calculators for question_type, calculator, relation in graph_element_prop_calculators: # check command type if sc_utils.checkIncToSets(session, question, [question_type], sc.SC_CONST): element = session.search_one_shot( session.sc_constraint_new(sc_constants.CONSTR_3_f_a_a, question, sc.SC_A_CONST, sc.SC_N_CONST), True, 3) if element is None: return element = element[2] graph = None arc = None it = session.create_iterator( session.sc_constraint_new(sc_constants.CONSTR_3_a_a_f, sc.SC_NODE, sc.SC_A_CONST | sc.SC_POS, element), True) while not it.is_over(): if sc_utils.checkIncToSets(session, it.value(0), [graph_keynodes.Common.graph], sc.SC_CONST): graph = it.value(0) arc = it.value(1) break it.next() if graph is None: continue # make graph and calculate property value g = Graph(segment, graph) sc2obj = g.makeNxGraph() result = calculator(g.graphNx, sc2obj[str(element.this)]) # if result is None: raise RuntimeWarning("Calculator can't calculate value") value = sc_utils.createNodeElement(session, segment, sc.SC_CONST) bin_rel = sc_utils.createPairBinaryOrientFull( session, segment, arc, value, sc.SC_CONST) a = sc_utils.createPairPosPerm(session, segment, relation, bin_rel[0], sc.SC_CONST) elements = translate_value(session, segment, value, result) elements.extend([value, graph, a, relation]) elements.extend(bin_rel) answer = sc_utils.createNodeElement(session, segment, sc.SC_CONST) for el in elements: sc_utils.createPairPosPerm(session, segment, answer, el, sc.SC_CONST) sc_utils.makeAnswer(session, segment, question, answer)