示例#1
0
def translate_circle(_segment, _object, _params):
    """Translates circle object to sc-memory
    """
    _addr = _object._getScAddr()
    
    # include sc-element to points
    session = core.Kernel.session()
    addToSets(session, _segment, _addr, [geom_keynodes.Objects.circle, keynodes.info.stype_ext_obj_abstract])    
    
    # add relation to center point
    addr_begin = _object.center_point._getScAddr()
    if not sc_utils.checkOutBinaryPairAttr(session, _addr, geom_keynodes.Relation.nrel_center, sc.SC_CONST):
        a1 = sc_utils.createPairBinaryOrient(session, _segment, _addr, addr_begin, sc.SC_CONST)
        sc_utils.createPairPosPerm(session, _segment, geom_keynodes.Relation.nrel_center, a1, sc.SC_CONST)
        
    if not sc_utils.checkOutBinaryPairAttr(session, _addr, geom_keynodes.Relation.nrel_radius, sc.SC_CONST):
        radius_obj = _object.getRadiusObject()
        if radius_obj is not None:
            a1 = sc_utils.createPairBinaryOrient(session, _segment, _addr, radius_obj._getScAddr(), sc.SC_CONST)
            sc_utils.createPairPosPerm(session, _segment, geom_keynodes.Relation.nrel_radius, a1, sc.SC_CONST)
    
    # translate child points
    translateChildPoints(session, _segment, _object)
    
    # translate radius if it exist
    
    return True
示例#2
0
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)
示例#3
0
def translate_line_sec(_segment, _object, _params):
    """Translates line section to sc-memory
    """
    _addr = _object._getScAddr()

    session = core.Kernel.session()
    if not _addr:
        _addr = sc_utils.createNodeStruct(session, _segment, sc.SC_CONST)
        _object._setScAddr(_addr)

    addToSets(session, _segment, _addr,
              [geom_keynodes.Objects.line_sector, keynodes.info.stype_struct])

    # end begin points
    addr_begin = _object.getBegin()._getScAddr()
    addr_end = _object.getEnd()._getScAddr()

    assert addr_begin and addr_end

    a1 = sc_utils.createPairBinaryOrient(session, _segment, _addr, addr_begin,
                                         sc.SC_CONST)
    sc_utils.createPairPosPerm(session, _segment,
                               geom_keynodes.Relation.nrel_border_point, a1,
                               sc.SC_CONST)
    a2 = sc_utils.createPairBinaryOrient(session, _segment, _addr, addr_end,
                                         sc.SC_CONST)
    sc_utils.createPairPosPerm(session, _segment,
                               geom_keynodes.Relation.nrel_border_point, a2,
                               sc.SC_CONST)

    # check if line have length and build it value
    # set value if it exists
    #    if _object.getLength() is not None:
    #        len_node = sc_utils.createNodeElement(session, _segment, sc.SC_CONST)
    #        sheaf = sc_utils.createPairBinaryOrient(session, _segment, _addr, len_node, sc.SC_CONST)
    #        sc_utils.createPairPosPerm(session, _segment, geom_keynodes.Relation.nrel_length, sheaf, sc.SC_CONST)
    #
    #        len_val_node = sc_utils.createNodeElement(session, _segment, sc.SC_CONST)
    #        sheaf = sc_utils.createPairBinaryOrient(session, _segment, len_val_node, len_node, sc.SC_CONST)
    #        sc_utils.createPairPosPerm(session, _segment, keynodes.common.nrel_value, sheaf, sc.SC_CONST)
    #
    #        len_val_cm_node = sc_utils.createNodeElement(session, _segment, sc.SC_CONST)
    #        a = sc_utils.createPairPosPerm(session, _segment, len_val_node, len_val_cm_node, sc.SC_CONST)
    #        sc_utils.createPairPosPerm(session, _segment, geom_keynodes.Relation.rrel_cm, a, sc.SC_CONST)
    #
    #        idtf_node = sc_utils.createNodeSheaf(session, _segment, sc.SC_CONST)
    #        sheaf = sc_utils.createPairBinaryOrient(session, _segment, idtf_node, len_val_cm_node, sc.SC_CONST)
    #        sc_utils.createPairPosPerm(session, _segment, keynodes.common.nrel_identification, sheaf, sc.SC_CONST)
    #
    #        dec_val_node = sc_utils.createNodeElement(session, _segment, sc.SC_CONST)
    #        session.set_content_real(dec_val_node, _object.getLength())
    #        a = sc_utils.createPairPosPerm(session, _segment, idtf_node, dec_val_node, sc.SC_CONST)
    #        sc_utils.createPairPosPerm(session, _segment, keynodes.common.rrel_dec_number, a, sc.SC_CONST)

    # translate child points
    translateChildPoints(session, _segment, _object)

    return True
示例#4
0
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
示例#5
0
def translate_line_sec(_segment, _object, _params):
    """Translates line section to sc-memory
    """
    _addr = _object._getScAddr()

    session = core.Kernel.session()
    if not _addr:   
        _addr = sc_utils.createNodeStruct(session, _segment, sc.SC_CONST)
        _object._setScAddr(_addr)
        
    addToSets(session, _segment, _addr, [geom_keynodes.Objects.line_sector, keynodes.info.stype_struct])
    
    # end begin points
    addr_begin = _object.getBegin()._getScAddr()
    addr_end = _object.getEnd()._getScAddr()
    
    assert addr_begin and addr_end
    
    a1 = sc_utils.createPairBinaryOrient(session, _segment, _addr, addr_begin, sc.SC_CONST)
    sc_utils.createPairPosPerm(session, _segment, geom_keynodes.Relation.nrel_border_point, a1, sc.SC_CONST)
    a2 = sc_utils.createPairBinaryOrient(session, _segment, _addr, addr_end, sc.SC_CONST)
    sc_utils.createPairPosPerm(session, _segment, geom_keynodes.Relation.nrel_border_point, a2, sc.SC_CONST)
    
    # check if line have length and build it value
        # set value if it exists
#    if _object.getLength() is not None:
#        len_node = sc_utils.createNodeElement(session, _segment, sc.SC_CONST)
#        sheaf = sc_utils.createPairBinaryOrient(session, _segment, _addr, len_node, sc.SC_CONST)
#        sc_utils.createPairPosPerm(session, _segment, geom_keynodes.Relation.nrel_length, sheaf, sc.SC_CONST)
#        
#        len_val_node = sc_utils.createNodeElement(session, _segment, sc.SC_CONST)
#        sheaf = sc_utils.createPairBinaryOrient(session, _segment, len_val_node, len_node, sc.SC_CONST)
#        sc_utils.createPairPosPerm(session, _segment, keynodes.common.nrel_value, sheaf, sc.SC_CONST)
#        
#        len_val_cm_node = sc_utils.createNodeElement(session, _segment, sc.SC_CONST)
#        a = sc_utils.createPairPosPerm(session, _segment, len_val_node, len_val_cm_node, sc.SC_CONST)
#        sc_utils.createPairPosPerm(session, _segment, geom_keynodes.Relation.rrel_cm, a, sc.SC_CONST)
#        
#        idtf_node = sc_utils.createNodeSheaf(session, _segment, sc.SC_CONST)
#        sheaf = sc_utils.createPairBinaryOrient(session, _segment, idtf_node, len_val_cm_node, sc.SC_CONST)
#        sc_utils.createPairPosPerm(session, _segment, keynodes.common.nrel_identification, sheaf, sc.SC_CONST)
#        
#        dec_val_node = sc_utils.createNodeElement(session, _segment, sc.SC_CONST)
#        session.set_content_real(dec_val_node, _object.getLength())
#        a = sc_utils.createPairPosPerm(session, _segment, idtf_node, dec_val_node, sc.SC_CONST)
#        sc_utils.createPairPosPerm(session, _segment, keynodes.common.rrel_dec_number, a, sc.SC_CONST)
    
    # translate child points
    translateChildPoints(session, _segment, _object)    
    
    return True
示例#6
0
def translate_quadrangle(_segment, _object, _params):
    """Translates circle object to sc-memory
    """
    _addr = _object._getScAddr()

    # include sc-element to points
    session = core.Kernel.session()
    addToSets(session, _segment, _addr, [
        geom_keynodes.Objects.plane_quadrangle,
        keynodes.info.stype_ext_obj_abstract
    ])

    sides = _object.getSides()
    for obj in sides:
        sheaf = sc_utils.createPairBinaryOrient(session, _segment, _addr,
                                                obj._getScAddr(), sc.SC_CONST)
        sc_utils.createPairPosPerm(session, _segment,
                                   geom_keynodes.Relation.nrel_side, sheaf,
                                   sc.SC_CONST)

    # build square relation
    #sq_node = sc_utils.createNodeElement(session, _segment, sc.SC_CONST)
    #sheaf = sc_utils.createPairBinaryOrient(session, _segment, _addr, sq_node, sc.SC_CONST)
    #sc_utils.createPairPosPerm(session, _segment, geom_keynodes.Relation.nrel_square, sheaf, sc.SC_CONST)

    return True
示例#7
0
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
示例#8
0
def translate_object(_segment, _object, _params):
    """Translates specified geometry object to SC-code.
    @param _segment:    segment to translate object in
    @type _segment:    sc_segment
    @param _object:    geometry object to translate
    @type _object:    SCgObject or SCgPair
    @param _params:    additional parameters to translate object. It contains list of sc-elements, that
    designates semantic types for specified object. sc-element, that designate translated object will be included to
    sets from _params
    @type _params:    list
    
    @return: if object translated successfully, then return True, else - False
    @rtype: bool
    """
    import suit.core.sc_utils as sc_utils
    session = core.Kernel.session()
    
    if isinstance(_object, chem_objects.ChemistryAtom):
        _addr = session.create_el(_segment, sc.SC_N_CONST)
        sc_utils.createPairPosPerm(session, _segment, getattr(chem_keynodes, "atom_%s" % _object._name), _addr, sc.SC_CONST)
        _object._setScAddr(_addr)
        
    elif isinstance(_object, chem_objects.ChemistryLink):
        _addr = session.create_el(_segment, sc.SC_N_CONST)
        sc_utils.createPairPosPerm(session, _segment, chem_keynodes.link, _addr, sc.SC_CONST)
        
        addr_begin = _object.getBegin()._getScAddr()
        addr_end = _object.getEnd()._getScAddr()
        
        assert addr_begin and addr_end
    
        a1 = sc_utils.createPairBinaryOrient(session, _segment, _addr, addr_begin, sc.SC_CONST)
        sc_utils.createPairPosPerm(session, _segment, chem_keynodes.linked_atom, a1, sc.SC_CONST)
        a2 = sc_utils.createPairBinaryOrient(session, _segment, _addr, addr_end, sc.SC_CONST)
        sc_utils.createPairPosPerm(session, _segment, chem_keynodes.linked_atom, a2, sc.SC_CONST)
        
        _object._setScAddr(_addr)
        
    
    return True
示例#9
0
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)
示例#10
0
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
示例#11
0
def translate_circle(_segment, _object, _params):
    """Translates circle object to sc-memory
    """
    _addr = _object._getScAddr()

    # include sc-element to points
    session = core.Kernel.session()
    addToSets(
        session, _segment, _addr,
        [geom_keynodes.Objects.circle, keynodes.info.stype_ext_obj_abstract])

    # add relation to center point
    addr_begin = _object.center_point._getScAddr()
    if not sc_utils.checkOutBinaryPairAttr(
            session, _addr, geom_keynodes.Relation.nrel_center, sc.SC_CONST):
        a1 = sc_utils.createPairBinaryOrient(session, _segment, _addr,
                                             addr_begin, sc.SC_CONST)
        sc_utils.createPairPosPerm(session, _segment,
                                   geom_keynodes.Relation.nrel_center, a1,
                                   sc.SC_CONST)

    if not sc_utils.checkOutBinaryPairAttr(
            session, _addr, geom_keynodes.Relation.nrel_radius, sc.SC_CONST):
        radius_obj = _object.getRadiusObject()
        if radius_obj is not None:
            a1 = sc_utils.createPairBinaryOrient(session, _segment, _addr,
                                                 radius_obj._getScAddr(),
                                                 sc.SC_CONST)
            sc_utils.createPairPosPerm(session, _segment,
                                       geom_keynodes.Relation.nrel_radius, a1,
                                       sc.SC_CONST)

    # translate child points
    translateChildPoints(session, _segment, _object)

    # translate radius if it exist

    return True
示例#12
0
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
示例#13
0
def translate_quadrangle(_segment, _object, _params):
    """Translates circle object to sc-memory
    """    
    _addr = _object._getScAddr()
    
    # include sc-element to points
    session = core.Kernel.session()
    addToSets(session, _segment, _addr, [geom_keynodes.Objects.plane_quadrangle, keynodes.info.stype_ext_obj_abstract])
 
    sides = _object.getSides()
    for obj in sides:
        sheaf = sc_utils.createPairBinaryOrient(session, _segment, _addr, obj._getScAddr(), sc.SC_CONST)
        sc_utils.createPairPosPerm(session, _segment, geom_keynodes.Relation.nrel_side, sheaf, sc.SC_CONST)
            
    # build square relation
    #sq_node = sc_utils.createNodeElement(session, _segment, sc.SC_CONST)
    #sheaf = sc_utils.createPairBinaryOrient(session, _segment, _addr, sq_node, sc.SC_CONST)
    #sc_utils.createPairPosPerm(session, _segment, geom_keynodes.Relation.nrel_square, sheaf, sc.SC_CONST)
    
    return True
示例#14
0
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
示例#15
0
    def expression(self, ):

        node = None

        a = None

        b = None


        try:
            try:
                # logic_gram.g:23:2: (a= atom ( '^' | '&' | ( '->' | '<-' ) | '<->' ) b= atom )
                # logic_gram.g:23:3: a= atom ( '^' | '&' | ( '->' | '<-' ) | '<->' ) b= atom
                pass 
                #action start
                   
                revers=None
                relation=None
                	
                #action end
                self._state.following.append(self.FOLLOW_atom_in_expression49)
                a = self.atom()

                self._state.following.pop()
                # logic_gram.g:26:10: ( '^' | '&' | ( '->' | '<-' ) | '<->' )
                alt2 = 4
                LA2 = self.input.LA(1)
                if LA2 == 6:
                    alt2 = 1
                elif LA2 == 7:
                    alt2 = 2
                elif LA2 == 8 or LA2 == 9:
                    alt2 = 3
                elif LA2 == 10:
                    alt2 = 4
                else:
                    nvae = NoViableAltException("", 2, 0, self.input)

                    raise nvae

                if alt2 == 1:
                    # logic_gram.g:26:11: '^'
                    pass 
                    self.match(self.input, 6, self.FOLLOW_6_in_expression52)
                    #action start
                    relation=logic_keynodes.Relation.nrel_disjunction
                    #action end


                elif alt2 == 2:
                    # logic_gram.g:27:3: '&'
                    pass 
                    self.match(self.input, 7, self.FOLLOW_7_in_expression57)
                    #action start
                    relation=logic_keynodes.Relation.nrel_conjunction
                    #action end


                elif alt2 == 3:
                    # logic_gram.g:28:3: ( '->' | '<-' )
                    pass 
                    # logic_gram.g:28:3: ( '->' | '<-' )
                    alt1 = 2
                    LA1_0 = self.input.LA(1)

                    if (LA1_0 == 8) :
                        alt1 = 1
                    elif (LA1_0 == 9) :
                        alt1 = 2
                    else:
                        nvae = NoViableAltException("", 1, 0, self.input)

                        raise nvae

                    if alt1 == 1:
                        # logic_gram.g:28:4: '->'
                        pass 
                        self.match(self.input, 8, self.FOLLOW_8_in_expression64)


                    elif alt1 == 2:
                        # logic_gram.g:28:9: '<-'
                        pass 
                        self.match(self.input, 9, self.FOLLOW_9_in_expression66)
                        #action start
                        revers=True
                        #action end



                    #action start
                    relation=logic_keynodes.Relation.nrel_implication
                    #action end


                elif alt2 == 4:
                    # logic_gram.g:29:3: '<->'
                    pass 
                    self.match(self.input, 10, self.FOLLOW_10_in_expression75)
                    #action start
                    relation=logic_keynodes.Relation.nrel_equivalence
                    #action end



                self._state.following.append(self.FOLLOW_atom_in_expression84)
                b = self.atom()

                self._state.following.pop()
                #action start
                  
                if relation==logic_keynodes.Relation.nrel_implication:
                	if revers:
                		a,b=b,a
                	node=sc_utils.createPairBinaryOrient(self.session, self.segment, a ,b, sc.SC_CONST)
                else:
                	node=sc_utils.createPairBinaryNoOrient(self.session, self.segment, a ,b, sc.SC_CONST)
                self.nodeList.append(node)
                self.nodeList.append(sc_utils.createPairPosPerm(self.session, self.segment,relation, node, sc.SC_CONST))
                	
                #action end




            except RecognitionException, re:
                self.reportError(re)
                self.recover(self.input, re)
        finally:

            pass
        return node
示例#16
0
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
示例#17
0
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