Exemplo n.º 1
0
/**
  * Finding function : returns all ModItem whom classname equals argument className.
  */
QList<ModItem*> ModItemsTree::findInDescendantsByClass(QString className,ModItem* parent)
{
    if(parent==NULL)
        parent = _rootElement;

    ModItem* curClass;
    QList<ModItem*> curClasses;
    int iChild;

    int curDepth = parent->depth();



    // then check children are readen
    if(!parent->childrenReaden())
    {
        // if not, check in its direction
        readFromOMCWThread(parent,curDepth+1,QString(),curDepth);
    }

    // looking if one child corresponds
    for(iChild=0; iChild<parent->childCount(); iChild++)
    {
        curClass = parent->child(iChild);
        if(curClass->getModClassName()==className)
            curClasses.push_back(curClass);

        //look deeper in children
        curClasses <<  findInDescendantsByClass(className,curClass);
    }

    return curClasses;

}
Exemplo n.º 2
0
/**
  * Finding function : returns all ModItem whom class equals or inherits className.
  */
QList<ModItem*> ModItemsTree::findInDescendantsByInheritedClass(QString className,ModItem* parent)
{
    if(parent==NULL)
        parent = _rootElement;

    ModItem* curChild;
    QString curChildClass;
    QList<ModItem*> result;
    int iChild;

    int curDepth = parent->depth();

    // then check children are readen
    if(!parent->childrenReaden())
    {
        // if not, check in its direction
        readFromOMCWThread(parent,curDepth+1,QString(),curDepth);
    }

    // looking if one child corresponds
    for(iChild=0;iChild<parent->childCount();iChild++)
    {
        curChild = parent->child(iChild);
        curChildClass = curChild->getModClassName();
        if((curChildClass==className)||_moomc->inherits(curChildClass,className))
            result.push_back(curChild);

        //look deeper in children
        result <<  findInDescendantsByInheritedClass(className,curChild);
    }

    return result;
}
Exemplo n.º 3
0
/**
  * Finding function : returns all components whom classname inherits argument className.
  */
QList<ModItem*> ModItemsTree::findCompOfInheritingClassInDescendants(QString className,ModItem* parent)
{
    if(parent==NULL)
        parent = _rootElement;

    ModItem* curComponent;
    QList<ModItem*> curComponents;
    int iChild;
    QString curCompClass;

    int curDepth = parent->depth();

    // then check children are readen
    if(!parent->childrenReaden())
    {
        // if not, check in its direction
        readFromOMCWThread(parent,curDepth+1,QString(),curDepth);
    }

    int nbCompChild = parent->compChildCount();
    int nbModelChild = parent->modelChildCount();
    int nbPackageChild = parent->packageChildCount();

    // looking if one child corresponds
    for(iChild=0;iChild<nbCompChild;iChild++)
    {
        curComponent = parent->compChild(iChild);
        curCompClass = curComponent->getModClassName();
        if((curCompClass==className)||_moomc->inherits(curCompClass,className))
            curComponents.push_back(curComponent);
    }

    //look deeper in components children
    iChild=0;
    while(iChild<nbCompChild)
    {
        curComponents <<  findCompOfInheritingClassInDescendants(className,parent->compChild(iChild));
        iChild++;
    }

    //look deeper in models children
    iChild=0;
    while(iChild<nbModelChild)
    {
        curComponents <<   findCompOfInheritingClassInDescendants(className,parent->modelChild(iChild));
        iChild++;
    }

    //look deeper in packages children
    iChild=0;
    while(iChild<nbPackageChild)
    {
        curComponents <<  findCompOfInheritingClassInDescendants(className,parent->packageChild(iChild));
        iChild++;
    }

    return curComponents;
}
Exemplo n.º 4
0
void ModItemsTree::fetchMore ( const QModelIndex & parent )
{
    if(!_enabled)
        return;

    if (!parent.isValid())
        return;

    ModItem *item = static_cast<ModItem*>(parent.internalPointer());

    if(item)
    {
        if(!item->childrenReaden())
            readFromOMCWThread(item,_modLoader->getDepthMax());
    }
}
Exemplo n.º 5
0
/**
* This function fills parent with its children. To achieve this, it calls MOOmc functions.
* @arg depthMax : maximum depth filling should go (each time functions goes in children, grand children...
* Depth is increased by one.
* @arg curDepth : current depth.
* @arg direction : allows to drive looking function along a path. This is especially used
* to look for deep modelas without covering all items.
*/
void ModItemsTree::readFromOmc(ModItem* parent,int depthMax,QString direction,int curDepth)
{
    if(parent->_readMutex.tryLock())
    {
        if((curDepth<=depthMax)&&!parent->childrenReaden())
        {
            ModItem* newElement;

            QString childrenDirection = direction.section(".",curDepth+1,curDepth+1);

            bool readPackages = (parent->getClassRestr()==Modelica::PACKAGE) || (parent->getClassRestr()==Modelica::GENERIC);
            bool readModels = (parent->getClassRestr()==Modelica::PACKAGE) || (parent->getClassRestr()==Modelica::GENERIC);
            bool readComponents = (parent->getClassRestr()==Modelica::MODEL) || (parent->getClassRestr()==Modelica::GENERIC) || (parent->getClassRestr()==Modelica::COMPONENT);
            bool readRecords = (parent->getClassRestr()==Modelica::PACKAGE) || (parent->getClassRestr()==Modelica::MODEL) ||(parent->getClassRestr()==Modelica::GENERIC)|| (parent->getClassRestr()==Modelica::COMPONENT);
            bool readClasses = readModels;

            QString fullParentName = parent->name(ModItem::FULL);
            QString parentClassName = parent->getModClassName();
            QString prefix;
            if(!fullParentName.isEmpty())
                prefix = fullParentName+".";

            // read packages
            if(readPackages)
            {
                QStringList packageNames = _moomc->getPackages(fullParentName);
                for(int i=0; i<packageNames.size(); i++)
                {
                    newElement = new ModPackage(_moomc,parent,prefix+packageNames.at(i));
                    if(addChild(parent,newElement))
                        if((childrenDirection=="") || (childrenDirection==packageNames.at(i)))
                            readFromOMCWThread(newElement,depthMax,direction,curDepth+1);
                }
            }

            // read models
            if(readModels)
            {
                QStringList modelNames = _moomc->getModels(fullParentName);
                for(int i=0; i<modelNames.size(); i++)
                {
                    newElement = new ModModel(_moomc,parent,prefix+modelNames.at(i));
                    if(addChild(parent,newElement))
                        if((childrenDirection=="") || (childrenDirection==modelNames.at(i)))
                            readFromOMCWThread(newElement,depthMax,direction,curDepth+1);
                }
            }

            // read records
            if(readRecords)
            {
                QStringList recordNames = _moomc->getRecords(fullParentName);
                for(int i=0; i<recordNames.size(); i++)
                {
                    newElement = new ModRecord(_moomc,parent,prefix+recordNames.at(i));
                    if(addChild(parent,newElement))
                        if((childrenDirection=="") || (childrenDirection==recordNames.at(i)))
                            readFromOMCWThread(newElement,depthMax,direction,curDepth+1);
                }
            }

            // read classes
            if(readClasses)
            {
                QStringList classNames = _moomc->getClasses(fullParentName);
                for(int i=0; i<classNames.size(); i++)
                {
                    newElement = new ModItem(_moomc,parent,prefix+classNames.at(i));
                    if(addChild(parent,newElement))
                        if((childrenDirection=="") || (childrenDirection==classNames.at(i)))
                            readFromOMCWThread(newElement,depthMax,direction,curDepth+1);
                }
            }

            //read components
            if(readComponents)
            {
                QStringList compNames;
                QStringList compClasses;
                _moomc->getContainedComponents(parentClassName,compNames,compClasses,true);
                for(int i=0; i<compNames.size(); i++)
                {
                    newElement = new ModComponent(_moomc,parent,prefix+compNames.at(i),compClasses.at(i));
                    if(addChild(parent,newElement))
                        if((childrenDirection=="") || (childrenDirection==compClasses.at(i)))
                            readFromOMCWThread(newElement,depthMax,direction,curDepth+1);
                }
            }
            parent->setChildrenReaden(true);
            parent->emitModified();
        }
        parent->_readMutex.unlock();
    }
}
Exemplo n.º 6
0
/**
  * Finding function : returns all components whom classname inherits argument className.
  * In a multimap since there are different classNames here.
  * @param classFilter : stop seeking in parent class does not go through this filter
  */
void  ModItemsTree::findCompOfInheritingClassesInDescendants(QStringList classNames,ModItem* parent,QMultiMap<QString,ModItem*> &result,QRegExp classFilter)
{
    if(parent==NULL)
        return;

    ModItem* curComponent;

    int iChild;
    QString curCompClass;

    QString parentClass = parent->getModClassName();
    if(classFilter.isValid() && !parentClass.contains(classFilter))
        return ;// no need to carry on

    int curDepth = parent->depth();
    // then check children are readen
    if(!parent->childrenReaden())
    {
        // if not, check in its direction
        readFromOMCWThread(parent,curDepth+1,QString(),curDepth);
    }

    int nbCompChild = parent->compChildCount();
    int nbModelChild = parent->modelChildCount();
    int nbPackageChild = parent->packageChildCount();

    // looking if one child corresponds
    for(iChild=0;iChild<nbCompChild;iChild++)
    {
        curComponent = parent->compChild(iChild);
        curCompClass = curComponent->getModClassName();

        foreach(QString  className, classNames)
        {
            if((curCompClass==className)||_moomc->inherits(curCompClass,className))
                result.insert(className,curComponent);
        }
    }

    //look deeper in components children
    iChild=0;
    while(iChild<nbCompChild)
    {
        findCompOfInheritingClassesInDescendants(classNames,parent->compChild(iChild),result);
        iChild++;
    }

    //look deeper in models children
    iChild=0;
    while(iChild<nbModelChild)
    {
        findCompOfInheritingClassesInDescendants(classNames,parent->modelChild(iChild),result);
        iChild++;
    }

    //look deeper in packages children
    iChild=0;
    while(iChild<nbPackageChild)
    {
        findCompOfInheritingClassesInDescendants(classNames,parent->packageChild(iChild),result);
        iChild++;
    }
}