예제 #1
0
bool AgentObserverMap::decode(QDataStream &in, TypesOfSubjects subject)
{
    bool ret = false;
    QString msg;
    in >> msg;

    // qDebug() << msg.split(PROTOCOL_SEPARATOR, QString::SkipEmptyParts);

    Attributes * attrib = 0;
    
    if (subject == TObsTrajectory)
    {
        attrib = getMapAttributes()->value("trajectory");
    }
    else
    {
		//@RAIAN: Neighborhood
		if(subject == TObsCell)
		{
			attrib = getMapAttributes()->value(className);
		}
		//@RAIAN: FIM
		else
		{
            // // ((subjectType == TObsAgent) || (subjectType == TObsAutomaton))
            // attrib = getMapAttributes()->value("currentState" + className);

            foreach (Attributes *attr, getMapAttributes()->values())
            {
                if (attr->getClassName() == className)
                {
                    attrib = attr;
                    break;
                }
            }
        }
    }
    if (attrib)
    {
        if (cleanImage)
            attrib->clear();

        ret = getProtocolDecoder().decode(msg, *attrib->getXsValue(), *attrib->getYsValue());
        // getPainterWidget()->plotMap(attrib);
    }
    qApp->processEvents();
    return ret;
}
예제 #2
0
/*
 GRAMMAR OF A TUPLE TYPE
 
 ‌ tuple-type → (tuple-type-bodyopt)
 ‌ tuple-type-body → tuple-type-element-list...opt
 ‌ tuple-type-element-list → tuple-type-element  tuple-type-element,tuple-type-element-list
 ‌ tuple-type-element → attributes opt inout opt type | inout opt element-name type-annotation
 ‌ element-name → identifier
 */
TupleTypePtr Parser::parseTupleType()
{
    Token token, token2;
    expect(L"(", token);
    TupleTypePtr ret = nodeFactory->createTupleType(token.state);
    Attributes attributes;
    if(!predicate(L")"))
    {
        do
        {
            //‌ tuple-type-element → attributes opt inout opt type inoutoptelement-nametype-annotation
            attributes.clear();
            bool inout = false;
            if(predicate(L"@"))
            {
                parseAttributes(attributes);
            }
            inout = match(Keyword::Inout);
            expect_next(token);
            if(attributes.empty() && token.type == TokenType::Identifier && token.identifier.keyword == Keyword::_ && peek(token2) && token2.type == TokenType::Colon)
            {
                //type-annotation → :attributes opt type
                if(predicate(L"@"))
                {
                    parseAttributes(attributes);
                }
                expect(L":");
                TypeNodePtr type = parseType();
                type->setAttributes(attributes);
                ret->add(inout, token.token, type);
            }
            else
            {
                restore(token);
                TypeNodePtr type = parseType();
                type->setAttributes(attributes);
                ret->add(inout, L"", type);
            }
        }while(match(L","));
        if(match(L"..."))
        {
            ret->setVariadicParameters(true);
        }
    }
    
    expect(L")");
    return ret;
}
예제 #3
0
bool ObserverMap::draw(QDataStream &state)
{
    bool decoded = false;
    QString msg;
    state >> msg;

    QList<Attributes *> listAttribs = mapAttributes->values();
    Attributes * attrib = 0;

    connectTreeLayerSlot(false);
    for (int i = 0; i < listAttribs.size(); i++)
    {
        attrib = listAttribs.at(i);
        if (attrib->getType() == TObsCell)
        {
            attrib->clear();

            decoded = protocolDecoder->decode(msg, *attrib->getXsValue(), *attrib->getYsValue());
            if (decoded)
                painterWidget->plotMap(attrib);
        }
        qApp->processEvents();
    }

    connectTreeLayerSlot(true);

    // cria a legenda e exibe na tela
	//@RAIAN: Troquei esta comparacao porque nao estava criando a legenda da segunda camada (No meu caso, a vizinhanca)
    //if (/*decoded &&*/ legendWindow && (builtLegend < 1))
	if ((legendWindow) && (builtLegend < mapAttributes->size()))
    {
	//@RAIAN: FIM
        connectTreeLayerSlot(false);
        legendWindow->makeLegend();
        showLayerLegend();

        painterWidget->replotMap();
        connectTreeLayerSlot(true);

        // exibe o zoom de janela
        zoomWindow();
        builtLegend++;
    }

    return decoded;
}
예제 #4
0
bool AgentObserverMap::unregistry(Subject *subj, const QString & className)
{
    if (! constainsItem(linkedSubjects, subj))
        return false;

#ifdef DEGUB_OBSERVER
    // qDebug() << "subjectAttributes " << subjectAttributes;
    // qDebug() << "linkedSubjects " << linkedSubjects;

    foreach(SubjectInterf *s, subjects)
        qDebug() << s->getSubjectType() << ", " << getSubjectName(s->getSubjectType());
#endif

    int idxItem = -1;
    for (int i = 0; i < linkedSubjects.size(); i++)
    {
        if (linkedSubjects.at(i).first == subj)
        {
            idxItem = i;
            break;
        }
    }
    linkedSubjects.remove(idxItem);

    // QTreeWidget * treeLayers = getTreeLayers();

    for (int i = 0; i < subjectAttributes.size(); i++)
    {
        if (getMapAttributes()->contains(subjectAttributes.at(i)))
        {
            Attributes *attrib = getMapAttributes()->value(subjectAttributes.at(i));
            
            if (className == attrib->getClassName())
            {
                attrib->clear();
                break;
            }
            /*
            // Remove apenas o atributo que não possui valores
            if (subj->getSubjectType() == attrib->getType())
            {
                qDebug() << "\nclassName " << className;
                qDebug() << "attrib->getExhibitionName() " << attrib->getExhibitionName();

                if ( (attrib->getType() != TObsAgent) 
                    || ((className == attrib->getExhibitionName()) && 
                         (! ObserverMap::existAgents(linkedSubjects)) ) )
                {
                    //for (int j = 0; j < treeLayers->topLevelItemCount(); j++)
                    //{
                    //    // Remove o atributo da árvore de layers
                    //    if ( treeLayers->topLevelItem(j)->text(0) == attrib->getName())
                    //    {
                    //        QTreeWidgetItem *treeItem = treeLayers->takeTopLevelItem(j);
                    //        delete treeItem;
                    //        break;
                    //    }
                    //}

                    // Remove o atributo do mapa de atributos
                    getMapAttributes()->take(attrib->getName());
                    getPainterWidget()->setExistAgent(false);
                    subjectAttributes.removeAt( subjectAttributes.indexOf(attrib->getName()) );
                    delete attrib;
                    return true;
                }
            }*/
        }
    }

    if (linkedSubjects.isEmpty())
        getPainterWidget()->setExistAgent(false);

    return true;
}