Search in sources :

Example 1 with MemberList

use of org.omg.space.xtce.AggregateDataType.MemberList in project CCDD by nasa.

the class CcddXTCEHandler method buildSpaceSystems.

/**
 ********************************************************************************************
 * Build the space systems
 *
 * @param node
 *            current tree node
 *
 * @param variableHandler
 *            variable handler class reference; null if includeVariablePaths is false
 *
 * @param separators
 *            string array containing the variable path separator character(s), show/hide data
 *            types flag ('true' or 'false'), and data type/variable name separator
 *            character(s); null if includeVariablePaths is false
 ********************************************************************************************
 */
private void buildSpaceSystems(String[] tableNames, CcddVariableSizeAndConversionHandler variableHandler, String[] separators) {
    List<StructureMemberList> memberLists = new ArrayList<StructureMemberList>();
    // Step through each table name
    for (String tableName : tableNames) {
        // Check if this is a child (instance) table
        if (!TableInformation.isPrototype(tableName)) {
            // TODO THIS NEEDS TO CHANGE SO THAT INSTANCE VALUES CAN BE USED
            // Get the prototype of the instance table. Only prototypes of the tables are
            // used to create the space systems
            tableName = TableInformation.getPrototypeName(tableName);
            // created
            if (getSpaceSystemByName(tableName, project.getValue()) != null) {
                // Skip this table since it's space system has already been created
                continue;
            }
        }
        // Get the information from the database for the specified table
        TableInformation tableInfo = dbTable.loadTableData(tableName, true, false, true, parent);
        // Check if the table's data successfully loaded
        if (!tableInfo.isErrorFlag()) {
            // TODO IF RATE INFORMATION GETS USED THEN THE PROTOTYPE DATA IS REQUIRED. SEPARATE
            // SPACE SYSTEMS FOR EACH INSTANCE MAY THEN BE NEEDED. THE SAME ISSUE APPLIES TO
            // OTHER INSTANCE VALUES (E.G., MIN & MAX) - CAN'T REFERENCE THE PROTOTYPE TO GET
            // THIS INFORMATION; INSTEAD NEED A SPACE SYSTEM FOR THE INSTANCE
            // Get the table type and from the type get the type definition. The type
            // definition can be a global parameter since if the table represents a structure,
            // then all of its children are also structures, and if the table represents
            // commands or other table type then it is processed within this nest level
            typeDefn = tableTypeHandler.getTypeDefinition(tableInfo.getType());
            // Check if the table type represents a structure or command
            if (typeDefn != null && (typeDefn.isStructure() || typeDefn.isCommand())) {
                // Replace all macro names with their corresponding values
                tableInfo.setData(macroHandler.replaceAllMacros(tableInfo.getData()));
                // Get the application ID data field value, if present
                String applicationID = fieldHandler.getFieldValue(tableName, InputDataType.MESSAGE_ID);
                // Get the name of the system to which this table belongs from the table's
                // system path data field (if present)
                String systemPath = fieldHandler.getFieldValue(tableName, InputDataType.SYSTEM_PATH);
                // Initialize the parent system to be the root (top-level) system
                SpaceSystemType parentSystem = project.getValue();
                // Check if a system path exists
                if (systemPath != null) {
                    // Step through each system name in the path
                    for (String systemName : systemPath.split("\\s*/\\s*")) {
                        // if present)
                        if (!systemName.isEmpty()) {
                            // Search the existing space systems for one with this system's
                            // name (if none exists then use the root system's name)
                            SpaceSystemType existingSystem = getSpaceSystemByName(systemName, parentSystem);
                            // Set the parent system to the existing system if found, else
                            // create a new space system using the name from the table's system
                            // path data field
                            parentSystem = existingSystem == null ? addSpaceSystem(parentSystem, systemName, null, classification2Attr, validationStatusAttr, versionAttr) : existingSystem;
                        }
                    }
                }
                // Add the space system
                parentSystem = addSpaceSystem(parentSystem, tableName, tableInfo.getDescription(), classification3Attr, validationStatusAttr, versionAttr);
                // Check if this is a structure table
                if (typeDefn.isStructure()) {
                    MemberList memberList = factory.createAggregateDataTypeMemberList();
                    // Get the default column indices
                    int varColumn = typeDefn.getColumnIndexByInputType(InputDataType.VARIABLE);
                    int typeColumn = typeDefn.getColumnIndexByInputType(InputDataType.PRIM_AND_STRUCT);
                    int sizeColumn = typeDefn.getColumnIndexByInputType(InputDataType.ARRAY_INDEX);
                    int bitColumn = typeDefn.getColumnIndexByInputType(InputDataType.BIT_LENGTH);
                    int enumColumn = typeDefn.getColumnIndexByInputType(InputDataType.ENUMERATION);
                    int descColumn = typeDefn.getColumnIndexByInputType(InputDataType.DESCRIPTION);
                    int unitsColumn = typeDefn.getColumnIndexByInputType(InputDataType.UNITS);
                    int minColumn = typeDefn.getColumnIndexByInputType(InputDataType.MINIMUM);
                    int maxColumn = typeDefn.getColumnIndexByInputType(InputDataType.MAXIMUM);
                    // Set the flag to indicate if this is the telemetry header table
                    boolean isTlmHeaderTable = tableName.equals(tlmHeaderTable);
                    // Check if this is the telemetry header table
                    if (isTlmHeaderTable) {
                        // Store the telemetry header's path
                        tlmHeaderPath = systemPath;
                    }
                    // Export the parameter container for this structure
                    addParameterContainer(parentSystem, tableInfo, varColumn, typeColumn, sizeColumn, isTlmHeaderTable, applicationID);
                    // Step through each row in the structure table
                    for (String[] rowData : tableInfo.getData()) {
                        // used to define the array)
                        if (!ArrayVariable.isArrayMember(rowData[varColumn])) {
                            // Add the variable to the space system
                            addParameter(parentSystem, rowData[varColumn], rowData[typeColumn], rowData[sizeColumn], rowData[bitColumn], (enumColumn != -1 && !rowData[enumColumn].isEmpty() ? rowData[enumColumn] : null), (unitsColumn != -1 && !rowData[unitsColumn].isEmpty() ? rowData[unitsColumn] : null), (minColumn != -1 && !rowData[minColumn].isEmpty() ? rowData[minColumn] : null), (maxColumn != -1 && !rowData[maxColumn].isEmpty() ? rowData[maxColumn] : null), (descColumn != -1 && !rowData[descColumn].isEmpty() ? rowData[descColumn] : null), (dataTypeHandler.isString(rowData[typeColumn]) && !rowData[sizeColumn].isEmpty() ? Integer.valueOf(rowData[sizeColumn].replaceAll("^.*(\\d+)$", "$1")) : 1));
                            // Use the variable name to create an aggregate list member and add
                            // it to the member list. The list is used if this structure is
                            // referenced as a data type in another structure
                            Member member = new Member();
                            member.setName(rowData[varColumn]);
                            member.setTypeRef("/" + project.getValue().getName() + (systemPath == null || systemPath.isEmpty() ? "" : "/" + systemPath) + "/" + tableName + "/" + getNameByDataType(rowData[varColumn], rowData[typeColumn]) + TYPE);
                            memberList.getMember().add(member);
                        }
                    }
                    // Check if any variables exists in the structure table
                    if (!memberList.getMember().isEmpty()) {
                        // Create a structure member list using the table's aggregate member
                        // list
                        memberLists.add(new StructureMemberList(tableName, memberList));
                    }
                } else // This is a command table
                {
                    // Get the list containing the associated column indices for each argument
                    // grouping
                    commandArguments = typeDefn.getAssociatedCommandArgumentColumns(false);
                    // Set the flag to indicate if this is the command header table
                    boolean isCmdHeaderTable = tableName.equals(cmdHeaderTable);
                    // Check if this is the command header table
                    if (isCmdHeaderTable) {
                        // Store the command header's path
                        cmdHeaderPath = systemPath;
                    }
                    // Add the command(s) from this table to the parent system
                    addSpaceSystemCommands(parentSystem, tableInfo, tableName.equals(cmdHeaderTable), applicationID);
                }
            }
        }
    }
    // Step through each table name
    for (String tableName : tableNames) {
        // Get the prototype for the child
        tableName = TableInformation.getPrototypeName(tableName);
        // Get the space system for this table
        SpaceSystemType spaceSystem = getSpaceSystemByName(tableName, project.getValue());
        // Check if the system was found and it has telemetry data
        if (spaceSystem != null && spaceSystem.getTelemetryMetaData() != null) {
            // Step through each parameter type
            for (NameDescriptionType type : spaceSystem.getTelemetryMetaData().getParameterTypeSet().getStringParameterTypeOrEnumeratedParameterTypeOrIntegerParameterType()) {
                // Check if the type is an aggregate (i.e., a structure reference)
                if (type instanceof AggregateDataType) {
                    // Remove the trailing text added to the table name that flags it as a type
                    // or array
                    String typeName = type.getName().substring(0, type.getName().lastIndexOf("_"));
                    // Step through each structure member list
                    for (StructureMemberList structMemList : memberLists) {
                        // Check if the aggregate refers to this structure
                        if (typeName.equals(structMemList.structureName)) {
                            // Set the aggregate's member list to this structure member list
                            // and stop searching
                            ((AggregateDataType) type).setMemberList(structMemList.memberList);
                            break;
                        }
                    }
                }
            }
        }
    }
}
Also used : MemberList(org.omg.space.xtce.AggregateDataType.MemberList) ArrayList(java.util.ArrayList) SpaceSystemType(org.omg.space.xtce.SpaceSystemType) NameDescriptionType(org.omg.space.xtce.NameDescriptionType) AggregateDataType(org.omg.space.xtce.AggregateDataType) TableInformation(CCDD.CcddClassesDataTable.TableInformation) Member(org.omg.space.xtce.AggregateDataType.MemberList.Member)

Aggregations

TableInformation (CCDD.CcddClassesDataTable.TableInformation)1 ArrayList (java.util.ArrayList)1 AggregateDataType (org.omg.space.xtce.AggregateDataType)1 MemberList (org.omg.space.xtce.AggregateDataType.MemberList)1 Member (org.omg.space.xtce.AggregateDataType.MemberList.Member)1 NameDescriptionType (org.omg.space.xtce.NameDescriptionType)1 SpaceSystemType (org.omg.space.xtce.SpaceSystemType)1