def translate_value(_segment, _value_node, _value): session = core.Kernel.session() v_node = sc_utils.createNodeElement(session, _segment, sc.SC_CONST) sheaf = sc_utils.createPairBinaryOrient(session, _segment, v_node, _value_node, sc.SC_CONST) sc_utils.createPairPosPerm(session, _segment, keynodes.common.nrel_value, sheaf, sc.SC_CONST) vu_node = sc_utils.createNodeElement(session, _segment, sc.SC_CONST) a = sc_utils.createPairPosPerm(session, _segment, v_node, vu_node, sc.SC_CONST) sc_utils.createPairPosPerm(session, _segment, geom_keynodes.Relation.rrel_cm2, a, sc.SC_CONST) # make identification idtf_node = sc_utils.createNodeSheaf(session, _segment, sc.SC_CONST) sheaf = sc_utils.createPairBinaryOrient(session, _segment, idtf_node, vu_node, sc.SC_CONST) sc_utils.createPairPosPerm(session, _segment, keynodes.common.nrel_identification, sheaf, sc.SC_CONST) # set value val = sc_utils.createNodeElement(session, _segment, sc.SC_CONST) sc_utils.setContentReal(session, _segment, val, _value) a = sc_utils.createPairPosPerm(session, _segment, idtf_node, val, sc.SC_CONST) sc_utils.createPairPosPerm(session, _segment, keynodes.common.rrel_dec_number, a, sc.SC_CONST)
def translate_value(session, _segment, _value_node, _value): """Setup value \p _value to \p _value_node @return: Return list of creates sc-elements """ v_node = sc_utils.createNodeElement(session, _segment, sc.SC_CONST) bin_pair = sc_utils.createPairBinaryOrientFull(session, _segment, v_node, _value_node, sc.SC_CONST) a = sc_utils.createPairPosPerm(session, _segment, keynodes.common.nrel_value, bin_pair[0], sc.SC_CONST) res = [v_node, a, keynodes.common.nrel_value] res.extend(bin_pair) vu_node = sc_utils.createNodeElement(session, _segment, sc.SC_CONST) a = sc_utils.createPairPosPerm(session, _segment, v_node, vu_node, sc.SC_CONST) res.extend([vu_node, a]) # make identification idtf_node = sc_utils.createNodeSheaf(session, _segment, sc.SC_CONST) bin_pair = sc_utils.createPairBinaryOrientFull(session, _segment, idtf_node, vu_node, sc.SC_CONST) a = sc_utils.createPairPosPerm(session, _segment, keynodes.common.nrel_identification, bin_pair[0], sc.SC_CONST) res.extend([idtf_node, a, keynodes.common.nrel_identification]) res.extend(bin_pair) # set value val = sc_utils.createNodeElement(session, _segment, sc.SC_CONST) sc_utils.setContentReal(session, _segment, val, _value) a = sc_utils.createPairPosPerm(session, _segment, idtf_node, val, sc.SC_CONST) a1 = sc_utils.createPairPosPerm(session, _segment, keynodes.common.rrel_dec_number, a, sc.SC_CONST) res.extend([val, a, a1, keynodes.common.rrel_dec_number]) return res
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 buildUserAtomQuestion(sc_qustions, sc_q_objects): # узел вопроса q_node = sc_utils.createNodeElement(session, segment, sc.SC_CONST) # добавляем во множество вопрос session.gen3_f_a_f(segment, sc_key.questions.question, q_node, sc.SC_A_CONST | sc.SC_POS) # добавляем во множество атомарный вопрос session.gen3_f_a_f(segment, sc_key.questions.atom, q_node, sc.SC_A_CONST | sc.SC_POS) # добавляем типы вопросов for sc_q in sc_qustions: session.gen3_f_a_f(segment, sc_q, q_node, sc.SC_A_CONST | sc.SC_POS) # добавляем объекты вопроса for sc_o in sc_q_objects: session.gen3_f_a_f(segment, q_node, sc_o, sc.SC_A_CONST | sc.SC_POS) # добавляем автора (пользователь) authors_node = sc_utils.createNodeElement(session, segment, sc.SC_CONST) sc_utils.createPairPosPerm(session, segment, authors_node, sc_core.Kernel.getSingleton().getUserAddr(), sc.SC_CONST) authors_pair_sheaf = sc_utils.createPairBinaryOrient( session, segment, q_node, authors_node, sc.SC_CONST) sc_utils.createPairPosPerm(session, segment, sc_key.common.nrel_authors, authors_pair_sheaf, sc.SC_CONST) # добавляем окна для вывода output_node = sc_utils.createNodeElement(session, segment, sc.SC_CONST) output_count = 0 it = session.create_iterator( session.sc_constraint_new(sc_constants.CONSTR_3_f_a_a, sc_key.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) #sc_utils.copySet(session, sc_key.ui.set_output_windows, output_node, segment) # link output windows set to question output_sheaf = sc_utils.createPairBinaryOrient(session, segment, output_node, q_node, sc.SC_CONST) sc_utils.createPairPosPerm(session, segment, sc_key.ui.nrel_set_of_output_windows, output_sheaf, sc.SC_CONST) # initiate question sc_utils.createPairPosPerm(session, segment, sc_key.questions.initiated, q_node, sc.SC_CONST) return q_node
def buildUserAtomQuestion(sc_qustions, sc_q_objects): # узел вопроса q_node = sc_utils.createNodeElement(session, segment, sc.SC_CONST) # добавляем во множество вопрос session.gen3_f_a_f(segment, sc_key.questions.question, q_node, sc.SC_A_CONST | sc.SC_POS) # добавляем во множество атомарный вопрос session.gen3_f_a_f(segment, sc_key.questions.atom, q_node, sc.SC_A_CONST | sc.SC_POS) # добавляем типы вопросов for sc_q in sc_qustions: session.gen3_f_a_f(segment, sc_q, q_node, sc.SC_A_CONST | sc.SC_POS) # добавляем объекты вопроса for sc_o in sc_q_objects: session.gen3_f_a_f(segment, q_node, sc_o, sc.SC_A_CONST | sc.SC_POS) # добавляем автора (пользователь) authors_node = sc_utils.createNodeElement(session, segment, sc.SC_CONST) sc_utils.createPairPosPerm(session, segment, authors_node, sc_core.Kernel.getSingleton().getUserAddr(), sc.SC_CONST) authors_pair_sheaf = sc_utils.createPairBinaryOrient(session, segment, q_node, authors_node, sc.SC_CONST) sc_utils.createPairPosPerm(session, segment, sc_key.common.nrel_authors, authors_pair_sheaf, sc.SC_CONST) # добавляем окна для вывода output_node = sc_utils.createNodeElement(session, segment, sc.SC_CONST) output_count = 0 it = session.create_iterator(session.sc_constraint_new(sc_constants.CONSTR_3_f_a_a, sc_key.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 ) #sc_utils.copySet(session, sc_key.ui.set_output_windows, output_node, segment) # link output windows set to question output_sheaf = sc_utils.createPairBinaryOrient(session, segment, output_node, q_node, sc.SC_CONST) sc_utils.createPairPosPerm(session, segment, sc_key.ui.nrel_set_of_output_windows, output_sheaf, sc.SC_CONST) # initiate question sc_utils.createPairPosPerm(session, segment, sc_key.questions.initiated, q_node, sc.SC_CONST) return q_node
def translate_value(session, _segment, _value_node, _value): """Setup value \p _value to \p _value_node @return: Return list of creates sc-elements """ v_node = sc_utils.createNodeElement(session, _segment, sc.SC_CONST) bin_pair = sc_utils.createPairBinaryOrientFull(session, _segment, v_node, _value_node, sc.SC_CONST) a = sc_utils.createPairPosPerm(session, _segment, keynodes.common.nrel_value, bin_pair[0], sc.SC_CONST) res = [v_node, a, keynodes.common.nrel_value] res.extend(bin_pair) vu_node = sc_utils.createNodeElement(session, _segment, sc.SC_CONST) a = sc_utils.createPairPosPerm(session, _segment, v_node, vu_node, sc.SC_CONST) res.extend([vu_node, a]) # make identification idtf_node = sc_utils.createNodeSheaf(session, _segment, sc.SC_CONST) bin_pair = sc_utils.createPairBinaryOrientFull(session, _segment, idtf_node, vu_node, sc.SC_CONST) a = sc_utils.createPairPosPerm(session, _segment, keynodes.common.nrel_identification, bin_pair[0], sc.SC_CONST) res.extend([idtf_node, a, keynodes.common.nrel_identification]) res.extend(bin_pair) # set value val = sc_utils.createNodeElement(session, _segment, sc.SC_CONST) sc_utils.setContentReal(session, _segment, val, _value) a = sc_utils.createPairPosPerm(session, _segment, idtf_node, val, sc.SC_CONST) a1 = sc_utils.createPairPosPerm(session, _segment, keynodes.common.rrel_dec_number, a, sc.SC_CONST) res.extend([val, a, a1, keynodes.common.rrel_dec_number]) return res
def buildUserAtomQuestion(sc_qustions, sc_q_objects): # узел вопроса q_node = sc_utils.createNodeElement(session, segment, sc.SC_CONST) # добавляем во множество вопрос session.gen3_f_a_f(segment, sc_key.questions.question, q_node, sc.SC_A_CONST | sc.SC_POS) # добавляем во множество атомарный вопрос session.gen3_f_a_f(segment, sc_key.questions.atom, q_node, sc.SC_A_CONST | sc.SC_POS) # добавляем типы вопросов for sc_q in sc_qustions: session.gen3_f_a_f(segment, sc_q, q_node, sc.SC_A_CONST | sc.SC_POS) # добавляем объекты вопроса for sc_o in sc_q_objects: session.gen3_f_a_f(segment, q_node, sc_o, sc.SC_A_CONST | sc.SC_POS) # добавляем автора (пользователь) authors_node = sc_utils.createNodeElement(session, segment, sc.SC_CONST) sc_utils.createPairPosPerm(session, segment, authors_node, sc_core.Kernel.getSingleton().getUserAddr(), sc.SC_CONST) authors_pair_sheaf = sc_utils.createPairBinaryOrient( session, segment, q_node, authors_node, sc.SC_CONST) sc_utils.createPairPosPerm(session, segment, sc_key.common.nrel_authors, authors_pair_sheaf, sc.SC_CONST) # добавляем окна для вывода output_node = sc_utils.createNodeElement(session, segment, sc.SC_CONST) sc_utils.copySet(session, sc_key.ui.set_output_windows, output_node, segment) # link output windows set to question output_sheaf = sc_utils.createPairBinaryOrient(session, segment, output_node, q_node, sc.SC_CONST) sc_utils.createPairPosPerm(session, segment, sc_key.ui.nrel_set_of_output_windows, output_sheaf, sc.SC_CONST) # initiate question sc_utils.createPairPosPerm(session, segment, sc_key.questions.initiated, q_node, sc.SC_CONST) return q_node
def translate_value(_segment, _value_node, _value): session = core.Kernel.session() v_node = sc_utils.createNodeElement(session, _segment, sc.SC_CONST) sheaf = sc_utils.createPairBinaryOrient(session, _segment, v_node, _value_node, sc.SC_CONST) sc_utils.createPairPosPerm(session, _segment, keynodes.common.nrel_value, sheaf, sc.SC_CONST) vu_node = sc_utils.createNodeElement(session, _segment, sc.SC_CONST) a = sc_utils.createPairPosPerm(session, _segment, v_node, vu_node, sc.SC_CONST) sc_utils.createPairPosPerm(session, _segment, geom_keynodes.Relation.rrel_cm2, a, sc.SC_CONST) # make identification idtf_node = sc_utils.createNodeSheaf(session, _segment, sc.SC_CONST) sheaf = sc_utils.createPairBinaryOrient(session, _segment, idtf_node, vu_node, sc.SC_CONST) sc_utils.createPairPosPerm(session, _segment, keynodes.common.nrel_identification, sheaf, sc.SC_CONST) # set value val = sc_utils.createNodeElement(session, _segment, sc.SC_CONST) sc_utils.setContentReal(session, _segment, val, _value) a = sc_utils.createPairPosPerm(session, _segment, idtf_node, val, sc.SC_CONST) sc_utils.createPairPosPerm(session, _segment, keynodes.common.rrel_dec_number, a, sc.SC_CONST)
def translate_length(_segment, _object): session = core.Kernel.session() _value = _object.getPropertyValue(geom_objects.GeometryAbstractObject.PropLength) _addr = _object._getScAddr() # build square relation if not sc_utils.checkOutBinaryPairAttr(session, _addr, geom_keynodes.Relation.nrel_length, sc.SC_CONST): p_node = sc_utils.createNodeElement(session, _segment, sc.SC_CONST) sheaf = sc_utils.createPairBinaryOrient(session, _segment, _addr, p_node, sc.SC_CONST) sc_utils.createPairPosPerm(session, _segment, geom_keynodes.Relation.nrel_length, sheaf, sc.SC_CONST) translate_value(_segment, p_node, _value) else: pass
def translate_length(_segment, _object): session = core.Kernel.session() _value = _object.getPropertyValue( geom_objects.GeometryAbstractObject.PropLength) _addr = _object._getScAddr() # build square relation if not sc_utils.checkOutBinaryPairAttr( session, _addr, geom_keynodes.Relation.nrel_length, sc.SC_CONST): p_node = sc_utils.createNodeElement(session, _segment, sc.SC_CONST) sheaf = sc_utils.createPairBinaryOrient(session, _segment, _addr, p_node, sc.SC_CONST) sc_utils.createPairPosPerm(session, _segment, geom_keynodes.Relation.nrel_length, sheaf, sc.SC_CONST) translate_value(_segment, p_node, _value) else: pass
def get_sel_elements_set(_session, _seg): """ Builds set of selected elements in active window @param _session: session to work with memory @type _session: sc_session @param _seg: segment to create set in @type _seg: sc_segment @return: tuple (sc_addr of selected elements set, list of elements that need to be added to question) @rtype: tuple """ sel_set = sc_utils.createNodeElement(_session, _seg, sc.SC_CONST) elements = [] # appending selected elements to set kernel = core.Kernel.getSingleton() sel_objs = kernel.rootSheet.getSelected() for obj in sel_objs: _addr = obj._getScAddr() elements.append(sc_utils.createPairPosPerm(_session, _seg, sel_set, _addr, sc.SC_CONST)) elements.append(_addr) return sel_set, elements
def get_arguments_set(_session, _seg): """Builds set of command aguments @param _session: session to work with sc-memory @type _session: sc_session @param _seg: segment to create set in @type _seg: sc_segment @return: tuple (sc_addr of arguments set, list of elements that need to be added to question) @rtype: tuple """ args_set = sc_utils.createNodeElement(_session, _seg, sc.SC_CONST) elements = [] # appending arguments to set kernel = core.Kernel.getSingleton() arg_objs = kernel.getArguments() for obj in arg_objs: _addr = obj._getScAddr() elements.append(sc_utils.createPairPosPerm(_session, _seg, args_set, _addr, sc.SC_CONST)) elements.append(_addr) return args_set, elements
def translate_impl(self, _input, _output): """Translator implementation """ errors = [] objs = objects.ScObject._sc2Objects(_input) assert len(objs) > 0 sheet = objs[0] assert isinstance(sheet, objects.ObjectSheet) seg = sheet.getTmpSegment() import suit.core.sc_utils as sc_utils errors = [] session = core.Kernel.session() # getting data and translate to sc field = sheet.getLogic().field print field # remove old objects for layer in field.layers: for item in layer.items: _addr = item._getScAddr() if _addr is not None: if _addr.seg.this == seg.this: item._setScAddr(None) session.erase_el(_addr) classifier = field.classifier _segs = [seg.get_full_uri()] _segs.extend(env.search_segments) for layer in field.layers: for item in layer.items: # if (not item.type in classifier.TYPES_TOWN): # continue # creating node in sc-memory _addr = sc_utils.createNodeElement(session, seg, sc.SC_CONST) item._setScAddr(_addr) if (item.type in classifier.TYPES_TOWN): sc_utils.createPairPosPerm(session, seg, map_keynodes.ObjectType.town, _addr, sc.SC_CONST) elif (item.type in classifier.TYPES_RAILWAY): sc_utils.createPairPosPerm(session, seg, map_keynodes.ObjectType.railway, _addr, sc.SC_CONST) elif item.type == classifier.TYPE_DISTRICT: sc_utils.createPairPosPerm( session, seg, map_keynodes.ObjectType.district, _addr, sc.SC_CONST) elif item.type == classifier.TYPE_AREA: sc_utils.createPairPosPerm(session, seg, map_keynodes.ObjectType.area, _addr, sc.SC_CONST) elif item.type in classifier.TYPES_ROAD: sc_utils.createPairPosPerm(session, seg, map_keynodes.ObjectType.road, _addr, sc.SC_CONST) for atribute in item.attributes: if ((atribute in classifier.atributes) and (item.attributes[atribute] != "")): _atr = sc_utils.getElementByIdtf( classifier.atributes[atribute], _segs) if _atr is None: _atr = sc_utils.createNodeRoleRelation( session, seg, sc.SC_CONST) session.set_idtf(_atr, classifier.atributes[atribute]) _val = sc_utils.getElementByIdtf( item.attributes[atribute], _segs) if _val is None: _val = sc_utils.createNodeElement( session, seg, sc.SC_CONST) session.set_idtf(_val, item.attributes[atribute]) #print classifier.atributes[atribute], item.attributes[atribute] pair = sc_utils.createPairPosPerm( session, seg, _addr, _val, sc.SC_CONST) sc_utils.createPairPosPerm(session, seg, _atr, pair, sc.SC_CONST) return errors
def createWindowFromNode(_node, _format, _is_edit): """Creates sc.g-window from sc.g-node @param _node: node to create window from @type _node: ScgNode @param _format: sc-element that designate format for node content @type _format: sc_global_addr @param _is_edit: flag to create editor @type _is_edit: boolean @return: window object @rtype: objects.ObjectSheet """ assert type(_node) is scg_objects.SCgNode session = core.Kernel.session() segment = core.Kernel.segment() parent = _node.parent # creating sc-element that designate window el = _node._getScAddr() if el is not None: # FIXME: changing type for variable session.change_type(el, sc.SC_N_CONST) else: el = sc_utils.createNodeElement(session, segment, sc.SC_CONST) sheet = objects.ObjectSheet() sheet._setScAddr(el) sheet.hideContent() logic = None if _is_edit: logic = core.Kernel.getSingleton().createEditor(_format) else: logic = core.Kernel.getSingleton().createViewer(_format) # including window to formats set sc_utils.createPairPosPerm(session, segment, _format, el, sc.SC_CONST) sheet.setLogic(logic) parent.addChild(sheet) sheet.setPosition(_node.getPosition()) # FIXME: removing for old window types _node._relinkToObject(sheet) parent._deleteObject(_node) # need to remove if _format.this == keynodes.ui.format_scgx.this: import suit.core.layout.LayoutGroupForceDirected as layout sheet.setLayoutGroup(layout.LayoutGroupForceSimple()) # linking by relation with parent # sheaf = sc_utils.createPairBinaryOrient(session, segment, parent._getScAddr(), el, sc.SC_CONST) # sc_utils.createPairPosPerm(session, segment, keynodes.ui.nrel_child_window, sheaf, sc.SC_CONST) return sheet
def translate_impl(self, _input, _output): """Translator implementation """ errors = [] objs = objects.ScObject._sc2Objects(_input) assert len(objs) > 0 sheet = objs[0] assert isinstance(sheet, objects.ObjectSheet) seg = sheet.getTmpSegment() import suit.core.sc_utils as sc_utils errors = [] session = core.Kernel.session() # getting data and translate to sc field = sheet.getLogic().field print field # remove old objects for layer in field.layers: for item in layer.items: _addr = item._getScAddr() if _addr is not None: if _addr.seg.this == seg.this: item._setScAddr(None) session.erase_el(_addr) classifier = field.classifier _segs = [seg.get_full_uri()] _segs.extend(env.search_segments) for layer in field.layers: for item in layer.items: # if (not item.type in classifier.TYPES_TOWN): # continue # creating node in sc-memory _addr = sc_utils.createNodeElement(session, seg, sc.SC_CONST) item._setScAddr(_addr) if (item.type in classifier.TYPES_TOWN): sc_utils.createPairPosPerm(session, seg, map_keynodes.ObjectType.town, _addr, sc.SC_CONST) elif (item.type in classifier.TYPES_RAILWAY): sc_utils.createPairPosPerm(session, seg, map_keynodes.ObjectType.railway, _addr, sc.SC_CONST) elif item.type == classifier.TYPE_DISTRICT: sc_utils.createPairPosPerm(session, seg, map_keynodes.ObjectType.district, _addr, sc.SC_CONST) elif item.type == classifier.TYPE_AREA: sc_utils.createPairPosPerm(session, seg, map_keynodes.ObjectType.area, _addr, sc.SC_CONST) elif item.type in classifier.TYPES_ROAD: sc_utils.createPairPosPerm(session, seg, map_keynodes.ObjectType.road, _addr, sc.SC_CONST) for atribute in item.attributes: if ((atribute in classifier.atributes) and (item.attributes[atribute]!="")): _atr=sc_utils.getElementByIdtf(classifier.atributes[atribute], _segs) if _atr is None: _atr = sc_utils.createNodeRoleRelation(session, seg, sc.SC_CONST) session.set_idtf(_atr, classifier.atributes[atribute]) _val=sc_utils.getElementByIdtf(item.attributes[atribute], _segs) if _val is None: _val = sc_utils.createNodeElement(session, seg, sc.SC_CONST) session.set_idtf(_val, item.attributes[atribute]) #print classifier.atributes[atribute], item.attributes[atribute] pair = sc_utils.createPairPosPerm(session, seg, _addr, _val, sc.SC_CONST) sc_utils.createPairPosPerm(session, seg, _atr, pair, sc.SC_CONST) 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)
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 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 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 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 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 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 generate_output_windows_set(_session, _segment, _parent_window): """Generates output windows set @param _session: session to work with sc-memory @type _session: MThreadSession @param _segment: segment in sc-memory to work in @type _segment: sc_segment @param _parent_window: parent window object @type _parent_window: ObjectSheet @return: output windows set @rtype: sc_global_addr """ import srs_engine.sc_utils as sc_utils # preparing for sc-machine working (translating it to SC-code) output_windows_set = sc_utils.createNodeElement(_session, _segment, sc.SC_CONST) kernel = core.Kernel.getSingleton() output_windows = kernel.getOutputWindows() import srs_engine.objects as objects for _addr, _exists, _edit in output_windows: window_node = _addr if not _exists: # creating new window window = objects.ObjectSheet() window.hideContent() if _edit: try: window.setLogic(kernel.createEditor(_addr)) except: print "There are no editor for addr %s" % (str(_addr)) window.setLogic(kernel.createViewer(_addr)) else: window.setLogic(kernel.createViewer(_addr)) kernel.mainWindow.addChild(window) sc_utils.createPairPosPerm(_session, _segment, _addr, window._getScAddr(), sc.SC_CONST) window_node = window._getScAddr() # test if _addr.this == keynodes.ui.format_scgx.this: import srs_engine.layout.LayoutGroupForceDirected as layout window.setLayoutGroup(layout.LayoutGroupForceSimple()) else: # test fmt = sc_utils.getContentFormat(_session, _addr) if fmt and fmt.this == keynodes.ui.format_scgx.this: import srs_engine.layout.LayoutGroupForceDirected as layout # FIXME: thinking about multiply objects for sc_addr windows = objects.ScObject._sc2Objects(_addr) assert len(windows) > 0 window = windows[0] if window.getLayoutGroup() is None: window.setLayoutGroup(layout.LayoutGroupForceSimple()) sc_utils.createPairPosPerm(_session, _segment, output_windows_set, window_node, sc.SC_CONST) # # test # import srs_engine.objects as objects # sheet = objects.ObjectSheet() # sheet.hideContent() # # sheet.setLogic(kernel.createEditor(keynodes.ui.format_scgx)) # kernel.rootSheet.addChild(sheet) # sc_utils.createPair(_session, kernel.segment(), keynodes.ui.format_scgx, sheet._getScAddr(), sc.SC_A_CONST | sc.SC_POS) # kernel.setRootSheet(sheet) # # import srs_engine.layout.LayoutGroupForceDirected as layout # sheet.setLayoutGroup(layout.LayoutGroupForceSimple()) # # test # # sc_utils.createPairPosPerm(_session, _segment, output_windows_set, sheet._getScAddr(), sc.SC_CONST) return output_windows_set
def generate_output_windows_set(_session, _segment, _parent_window): """Generates output windows set @param _session: session to work with sc-memory @type _session: MThreadSession @param _segment: segment in sc-memory to work in @type _segment: sc_segment @param _parent_window: parent window object @type _parent_window: ObjectSheet @return: output windows set @rtype: sc_global_addr """ import srs_engine.sc_utils as sc_utils # preparing for sc-machine working (translating it to SC-code) output_windows_set = sc_utils.createNodeElement(_session, _segment, sc.SC_CONST) kernel = core.Kernel.getSingleton() output_windows = kernel.getOutputWindows() import srs_engine.objects as objects for _addr, _exists, _edit in output_windows: window_node = _addr if not _exists: # creating new window window = objects.ObjectSheet() window.hideContent() if _edit: try: window.setLogic(kernel.createEditor(_addr)) except: print "There are no editor for addr %s" % (str(_addr)) window.setLogic(kernel.createViewer(_addr)) else: window.setLogic(kernel.createViewer(_addr)) kernel.mainWindow.addChild(window) sc_utils.createPairPosPerm(_session, _segment, _addr, window._getScAddr(), sc.SC_CONST) window_node = window._getScAddr() # test if _addr.this == keynodes.ui.format_scgx.this: import srs_engine.layout.LayoutGroupForceDirected as layout window.setLayoutGroup(layout.LayoutGroupForceSimple()) else: # test fmt = sc_utils.getContentFormat(_session, _addr) if fmt and fmt.this == keynodes.ui.format_scgx.this: import srs_engine.layout.LayoutGroupForceDirected as layout # FIXME: thinking about multiply objects for sc_addr windows = objects.ScObject._sc2Objects(_addr) assert len(windows) > 0 window = windows[0] if window.getLayoutGroup() is None: window.setLayoutGroup(layout.LayoutGroupForceSimple()) sc_utils.createPairPosPerm(_session, _segment, output_windows_set, window_node, sc.SC_CONST) # # test # import srs_engine.objects as objects # sheet = objects.ObjectSheet() # sheet.hideContent() # # sheet.setLogic(kernel.createEditor(keynodes.ui.format_scgx)) # kernel.rootSheet.addChild(sheet) # sc_utils.createPair(_session, kernel.segment(), keynodes.ui.format_scgx, sheet._getScAddr(), sc.SC_A_CONST | sc.SC_POS) # kernel.setRootSheet(sheet) # # import srs_engine.layout.LayoutGroupForceDirected as layout # sheet.setLayoutGroup(layout.LayoutGroupForceSimple()) # # test # # sc_utils.createPairPosPerm(_session, _segment, output_windows_set, sheet._getScAddr(), sc.SC_CONST) return output_windows_set