Search in sources :

Example 6 with SpaceSystemType

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

the class CcddXTCEHandler method createTableTypeDefinitions.

/**
 ********************************************************************************************
 * Scan the import file in order to determine if any structure or command tables exist. If so,
 * create the structure and/or command table type definition that's used to build the new
 * tables
 *
 * @param rootSystem
 *            root space system
 *
 * @param importFileName
 *            import file name
 ********************************************************************************************
 */
private void createTableTypeDefinitions(SpaceSystemType rootSystem, ImportType importType) {
    isTelemetry = false;
    isCommand = false;
    maxNumArguments = 1;
    // Step through each space system
    for (SpaceSystemType system : rootSystem.getSpaceSystem()) {
        // Recursively step through the XTCE-formatted data and extract the telemetry and
        // command information
        findMetaData(system, importType);
    }
    // Check if a structure table is defined in the import file
    if (isTelemetry) {
        String typeName = "XTCE Structure";
        int sequence = 2;
        // Continue to check while a table type with this name exists
        while (tableTypeHandler.getTypeDefinition(typeName) != null) {
            // Alter the name so that there isn't a duplicate
            typeName = "XTCE Structure " + sequence;
            sequence++;
        }
        // Create the XTCE structure table type using the default structure columns
        structureTypeDefn = tableTypeHandler.createTypeDefinition(typeName, DefaultColumn.getDefaultColumnDefinitions(TYPE_STRUCTURE), "XTCE import structure table type");
        // Get the current number of columns defined for the structure table type. The new
        // columns are appended to the existing ones
        int columnIndex = structureTypeDefn.getColumnCountDatabase();
        // Add the minimum and maximum value columns
        structureTypeDefn.addColumn(columnIndex, structureTypeDefn.getColumnNameDatabase(COL_MINIMUM, InputDataType.MINIMUM), COL_MINIMUM, "Minimum value", InputDataType.MINIMUM, false, false, false, true);
        structureTypeDefn.addColumn(columnIndex + 1, structureTypeDefn.getColumnNameDatabase(COL_MAXIMUM, InputDataType.MAXIMUM), COL_MAXIMUM, "Maximum value", InputDataType.MAXIMUM, false, false, false, true);
        // Get structure table column indices
        variableNameIndex = CcddTableTypeHandler.getVisibleColumnIndex(structureTypeDefn.getColumnIndexByInputType(InputDataType.VARIABLE));
        dataTypeIndex = CcddTableTypeHandler.getVisibleColumnIndex(structureTypeDefn.getColumnIndexByInputType(InputDataType.PRIM_AND_STRUCT));
        arraySizeIndex = CcddTableTypeHandler.getVisibleColumnIndex(structureTypeDefn.getColumnIndexByInputType(InputDataType.ARRAY_INDEX));
        bitLengthIndex = CcddTableTypeHandler.getVisibleColumnIndex(structureTypeDefn.getColumnIndexByInputType(InputDataType.BIT_LENGTH));
        enumerationIndex = CcddTableTypeHandler.getVisibleColumnIndex(structureTypeDefn.getColumnIndexByInputType(InputDataType.ENUMERATION));
        minimumIndex = CcddTableTypeHandler.getVisibleColumnIndex(structureTypeDefn.getColumnIndexByInputType(InputDataType.MINIMUM));
        maximumIndex = CcddTableTypeHandler.getVisibleColumnIndex(structureTypeDefn.getColumnIndexByInputType(InputDataType.MAXIMUM));
        descriptionIndex = CcddTableTypeHandler.getVisibleColumnIndex(structureTypeDefn.getColumnIndexByInputType(InputDataType.DESCRIPTION));
        unitsIndex = CcddTableTypeHandler.getVisibleColumnIndex(structureTypeDefn.getColumnIndexByInputType(InputDataType.UNITS));
        // Get the number of columns defined in the structure table type
        numStructureColumns = structureTypeDefn.getColumnCountVisible();
    }
    // Check if a command table is defined in the import file
    if (isCommand) {
        String typeName = "XTCE Command";
        int sequence = 2;
        // Continue to check while a table type with this name exists
        while (tableTypeHandler.getTypeDefinition(typeName) != null) {
            // Alter the name so that there isn't a duplicate
            typeName = "XTCE Command " + sequence;
            sequence++;
        }
        // Create the XTCE command table type using the default command columns
        commandTypeDefn = tableTypeHandler.createTypeDefinition(typeName, DefaultColumn.getDefaultColumnDefinitions(TYPE_COMMAND), "XTCE import command table type");
        // Step through each additional command argument column set
        for (int argIndex = 2; argIndex < maxNumArguments; argIndex++) {
            // Add the default columns for this command argument
            commandTypeDefn.addCommandArgumentColumns(argIndex);
        }
        // Get the list containing the associated column indices for each argument grouping
        commandArguments = commandTypeDefn.getAssociatedCommandArgumentColumns(true);
        // Get the command table column indices
        commandNameIndex = CcddTableTypeHandler.getVisibleColumnIndex(commandTypeDefn.getColumnIndexByInputType(InputDataType.COMMAND_NAME));
        commandCodeIndex = CcddTableTypeHandler.getVisibleColumnIndex(commandTypeDefn.getColumnIndexByInputType(InputDataType.COMMAND_CODE));
        cmdDescriptionIndex = CcddTableTypeHandler.getVisibleColumnIndex(commandTypeDefn.getColumnIndexByInputType(InputDataType.DESCRIPTION));
        // Get the number of columns defined in the command table type
        numCommandColumns = commandTypeDefn.getColumnCountVisible();
    }
}
Also used : SpaceSystemType(org.omg.space.xtce.SpaceSystemType)

Example 7 with SpaceSystemType

use of org.omg.space.xtce.SpaceSystemType 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

SpaceSystemType (org.omg.space.xtce.SpaceSystemType)7 Date (java.util.Date)2 CommandMetaDataType (org.omg.space.xtce.CommandMetaDataType)2 AncillaryDataSet (org.omg.space.xtce.DescriptionType.AncillaryDataSet)2 AncillaryData (org.omg.space.xtce.DescriptionType.AncillaryDataSet.AncillaryData)2 TelemetryMetaDataType (org.omg.space.xtce.TelemetryMetaDataType)2 TableDefinition (CCDD.CcddClassesDataTable.TableDefinition)1 TableInformation (CCDD.CcddClassesDataTable.TableInformation)1 ArrayList (java.util.ArrayList)1 JAXBElement (javax.xml.bind.JAXBElement)1 JAXBException (javax.xml.bind.JAXBException)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 MetaCommandSet (org.omg.space.xtce.CommandMetaDataType.MetaCommandSet)1 AuthorSet (org.omg.space.xtce.HeaderType.AuthorSet)1 NoteSet (org.omg.space.xtce.HeaderType.NoteSet)1 MetaCommandType (org.omg.space.xtce.MetaCommandType)1 NameDescriptionType (org.omg.space.xtce.NameDescriptionType)1