示例#1
0
QStringList CellmlFileRuntime::componentHierarchy(iface::cellml_api::CellMLElement *pElement)
{
    // Make sure that we have a given element

    if (!pElement)
        return QStringList();

    // Try to retrieve the component that owns the given element, unless the
    // given element is a component itself (which will be the case when we come
    // here through recursion)

    ObjRef<iface::cellml_api::CellMLComponent> component = QueryInterface(pElement);
    ObjRef<iface::cellml_api::CellMLElement> parent = pElement->parentElement();
    ObjRef<iface::cellml_api::CellMLComponent> parentComponent = QueryInterface(parent);

    if (!component && !parentComponent) {
        // The element isn't a component and neither is its parent, so it
        // doesn't have a hierarchy

        return QStringList();
    }

    // Recursively retrieve the component hierarchy of the given element's
    // encapsulation parent, if any

    ObjRef<iface::cellml_api::CellMLComponent> componentEncapsulationParent = component?component->encapsulationParent():parentComponent->encapsulationParent();

    return componentHierarchy(componentEncapsulationParent) << QString::fromStdWString(component?component->name():parentComponent->name());
}
示例#2
0
QStringList CellmlFileRuntime::componentHierarchy(iface::cellml_api::CellMLElement *pElement)
{
    // Make sure that we have a given element

    if (!pElement)
        return QStringList();

    // Try to retrieve the component that owns the given element, unless the
    // given element is a component itself (which will be the case when we come
    // here through recursion)

    ObjRef<iface::cellml_api::CellMLComponent> component = QueryInterface(pElement);

    ObjRef<iface::cellml_api::CellMLElement> parent = pElement->parentElement();
    ObjRef<iface::cellml_api::CellMLComponent> parentComponent = QueryInterface(parent);

    if (!component && !parentComponent) {
        // The element isn't a component and neither is its parent, so it
        // doesn't have a hierarchy

        return QStringList();
    }

    // Check whether this is an imported component and, if so, retrieve its
    // imported name

    QString componentName = QString::fromStdWString(component?component->name():parentComponent->name());

    ObjRef<iface::cellml_api::CellMLElement> componentParent = component?component->parentElement():parentComponent->parentElement();
    ObjRef<iface::cellml_api::CellMLElement> componentParentParent = componentParent->parentElement();

    if (componentParentParent) {
        // The given element comes from or is an imported component, so go
        // through our different imported components and look for the one we are
        // after

        ObjRef<iface::cellml_api::CellMLImport> import = QueryInterface(componentParentParent);
        ObjRef<iface::cellml_api::ImportComponentSet> importComponents = import->components();
        ObjRef<iface::cellml_api::ImportComponentIterator> importComponentsIter = importComponents->iterateImportComponents();

        for (ObjRef<iface::cellml_api::ImportComponent> importComponent = importComponentsIter->nextImportComponent();
             importComponent; importComponent = importComponentsIter->nextImportComponent()) {
            if (!componentName.compare(QString::fromStdWString(importComponent->componentRef()))) {
                // This is the imported component we are after, so retrieve its
                // imported name

                componentName = QString::fromStdWString(importComponent->name());

                break;
            }
        }
    }

    // Recursively retrieve the component hierarchy of the given element's
    // encapsulation parent, if any

    ObjRef<iface::cellml_api::CellMLComponent> componentEncapsulationParent = component?component->encapsulationParent():parentComponent->encapsulationParent();

    return componentHierarchy(componentEncapsulationParent) << componentName;
}