Example #1
0
/**
  * Finding function : within parent, look for children whom fullname equals argument
  */
ModItem* ModItemsTree::findInDescendants(QString fullName,ModItem* parent)
{
    if(parent==NULL)
        parent = _rootElement;

    ModItem* curChild;
    QString curFullName = parent->name(ModItem::FULL);

    int curDepth = parent->depth();
    int lookingDepth = fullName.split(".").size()-1;

    // check if it is this component
    if(curFullName == fullName)
        return parent;

    //first check name compatibility
    if(fullName.indexOf(curFullName)!=0)
        return NULL;

    // then check children are readen
    if(!parent->childrenReaden())
    {
        // if not, check in its direction
        readFromOmc(parent,lookingDepth,fullName,curDepth);
    }

    //get child name to visit
    //QString childShortName = fullName.section(".",curDepth,curDepth);
    QString childShortName = fullName;
    // first remove parent name
    // A ajouter la une condition if not executable else childShortName = curFullName !!!!!!
    if(!fullName.endsWith(".exe"))
    {
        childShortName.remove(QRegExp("^"+curFullName+"\\."));
        // then take first section
        childShortName = childShortName.section(".",0,0);


        // looking in children
        for(int iChild=0;iChild<parent->childCount();iChild++)
        {
            curChild = parent->child(iChild);
            if(curChild->name(ModItem::SHORT)==childShortName)
                return findInDescendants(fullName,curChild);
        }
    }
    else
    {
        for(int iChild=0;iChild<parent->childCount();iChild++)
        {
            curChild = parent->child(iChild);
            if(curChild->name(ModItem::FULL)==childShortName)
                return findInDescendants(fullName,curChild);
        }


    }
    return NULL;
}
Example #2
0
ModItem* ModItemsTree::findItem(QString fullName)
{
    return findInDescendants(fullName,_rootElement);
}
Example #3
0
/**
* \brief
* Return first ModModel in item parents (including himself).
* This function can for instance be used to know which model compile
* in order to update item value.
* @param itemName : full name of item whom who are looking parent model
*/
ModModel* ModItemsTree::modelOf(QString itemName)
{
    ModItem* item = findInDescendants(itemName);
    return modelOf(item);
}
Example #4
0
/**
  * Returns whether or not a ModItem is in this tree.
  */
bool ModItemsTree::isInDescendants(QString fullName,ModItem* parent)
{
    ModItem* foundClass = findInDescendants(fullName,parent);
    return (bool)(foundClass);
}
Example #5
0
/**
  * Another version of readFromOmc.
  * @sa readFromOmc
  * @todo benchmark reading functions
  */
void ModItemsTree::readFromOmcV3(ModItem* parent,int depthMax,QString direction,int curDepth)
{
    if(parent->_readMutex.tryLock())
    {
        if((curDepth<=depthMax)&&!parent->childrenReaden())
        {
            QString childrenDirection = direction.section(".",curDepth+1,curDepth+1);
            QString fullParentClass = parent->getModClassName();
            QString fullParentName = parent->name(ModItem::FULL);


            QString prefix;
            if(!fullParentName.isEmpty())
                prefix = fullParentName+".";

            ModItem* newElement;

            //read packages, models and components
            QStringList packagesClasses,modelsClasses,recordsNames,compsNames,compsClasses;
            bool foundInLib = false;


            ModItem* _corrLibComp = findInDescendants(fullParentName);
            if(_corrLibComp)
            {
                // If class is already loaded in package, use its information
                foundInLib = true;
                childrenInfos(_corrLibComp,packagesClasses,modelsClasses,recordsNames,compsNames,compsClasses);
            }
            else
            {
                // Call parent->_moomc
                _moomc->readElementInfos(fullParentClass,packagesClasses,modelsClasses,recordsNames,compsNames,compsClasses);
                // get inherited components
                QStringList inheritedCompNames,inheritedCompClasses;
                _moomc->getInheritedComponents(fullParentClass,inheritedCompNames,inheritedCompClasses);
                compsNames << inheritedCompNames;
                compsClasses << inheritedCompClasses;
            }


            // adding child packages and read them
            for(int i=0; i<packagesClasses.size(); i++)
            {
                newElement = new ModPackage(_moomc,parent,prefix+packagesClasses.at(i));
                if(addChild(parent,newElement))
                    if((childrenDirection=="") || (childrenDirection==packagesClasses.at(i)))
                        readFromOmcV3(newElement,depthMax,direction,curDepth+1);
            }

            // adding child models and read them
            for(int i=0; i<modelsClasses.size(); i++)
            {
                newElement = new ModModel(_moomc,parent,prefix+modelsClasses.at(i));
                if(addChild(parent,newElement))
                    if((childrenDirection=="") || (childrenDirection==modelsClasses.at(i)))
                        readFromOmcV3(newElement,depthMax,direction,curDepth+1);
            }

            // adding child components and read them
            for(int i=0; i<compsNames.size(); i++)
            {
                newElement = new ModComponent(_moomc,parent,prefix+compsNames.at(i),compsClasses.at(i));
                if(addChild(parent,newElement))
                    if((childrenDirection=="") || (childrenDirection==compsClasses.at(i)))
                        readFromOmcV3(newElement,depthMax,direction,curDepth+1);
            }

            parent->setChildrenReaden(true);
            parent->emitModified();

        }
        parent->_readMutex.unlock();
    }
}