Search in sources :

Example 1 with BitPackNodeIndex

use of CCDD.CcddClassesDataTable.BitPackNodeIndex in project CCDD by nasa.

the class CcddCommonTreeHandler method addChildNodes.

/**
 ********************************************************************************************
 * Recursively add the children of the specified node to the path list. If these are variable
 * paths and the node represents a bit-wise or string variable then add the bit-packed/string
 * members as well
 *
 * @param node
 *            current child node to check
 *
 * @param selectedPaths
 *            list containing the selected paths
 *
 * @param excludedPaths
 *            list of paths to be excluded from the tree
 *
 * @param isVariable
 *            true if the tree contains variables
 ********************************************************************************************
 */
protected void addChildNodes(ToolTipTreeNode node, List<Object[]> selectedPaths, List<String> excludedPaths, boolean isVariable) {
    // Check if this node has no children
    if (node.getChildCount() == 0) {
        boolean isAdded = false;
        // Get the node name to shorten subsequent calls
        String nodeName = node.getUserObject().toString();
        // as excluded (i.e., starts with an HTML tag)
        if (excludedPaths == null || !nodeName.startsWith("<html>")) {
            // siblings
            if (node.getSiblingCount() > 1) {
                BitPackNodeIndex nodeIndex = null;
                // Check if this is a variable tree
                if (isVariable) {
                    // Check if it represents a bit-wise variable
                    if (nodeName.contains(":")) {
                        // Get the node indices that encompass the packed variables (if
                        // applicable)
                        nodeIndex = getBitPackedVariables(node);
                    } else // Not a bit-wise variable
                    {
                        // Extract the data type name form the node name
                        String dataType = nodeName.substring(0, nodeName.indexOf("."));
                        // Check if this is a string
                        if (dataTypeHandler.isString(dataType)) {
                            // Get the node indices that encompass the string array members
                            nodeIndex = getStringVariableMembers(node);
                        }
                    }
                }
                // Check if packed variables or string members are present
                if (nodeIndex != null) {
                    // Calculate the tree node index for the first packed/string variable
                    int treeIndex = node.getParent().getIndex(node) - (nodeIndex.getTableIndex() - nodeIndex.getFirstIndex());
                    // Step through each packed/string variable
                    for (int index = nodeIndex.getFirstIndex(); index <= nodeIndex.getLastIndex(); index++, treeIndex++) {
                        boolean isInList = false;
                        // Get the path for the variable
                        Object[] path = ((ToolTipTreeNode) node.getParent().getChildAt(treeIndex)).getPath();
                        // Step through the paths already added
                        for (Object[] selPath : selectedPaths) {
                            // Check if the path is already in the list
                            if (Arrays.equals(path, selPath)) {
                                // Set the flag to indicate the path is already in the list and
                                // stop searching
                                isInList = true;
                                break;
                            }
                        }
                        // Check if the variable wasn't already in the list
                        if (!isInList) {
                            // Add the variable to the selected variables list
                            selectedPaths.add(path);
                        }
                    }
                    // Set the flag indicating the variable is added
                    isAdded = true;
                }
            }
            // Check if the variable isn't already added above
            if (!isAdded) {
                // Add the variable path to the list
                selectedPaths.add(node.getPath());
            }
        }
    } else // The node has child nodes
    {
        // Step through each child node
        for (int index = 0; index < node.getChildCount(); index++) {
            // Check if the child node has children
            addChildNodes((ToolTipTreeNode) node.getChildAt(index), selectedPaths, excludedPaths, isVariable);
        }
    }
}
Also used : BitPackNodeIndex(CCDD.CcddClassesDataTable.BitPackNodeIndex) ToolTipTreeNode(CCDD.CcddClassesComponent.ToolTipTreeNode)

Example 2 with BitPackNodeIndex

use of CCDD.CcddClassesDataTable.BitPackNodeIndex in project CCDD by nasa.

the class CcddTelemetrySchedulerInput method getSelectedVariableSize.

/**
 ********************************************************************************************
 * Get the total number of bytes of the specified or selected variable(s)
 *
 * @param variables
 *            list of variables; null to use the currently selected variable(s)
 *
 * @return Total number of bytes of the specified variable(s)
 ********************************************************************************************
 */
@Override
public int getSelectedVariableSize(List<Variable> variables) {
    // Check if no variable list is provided
    if (variables == null) {
        // Use the currently selected variables
        variables = getSelectedVariable();
    }
    // Initialize the total number of bytes remaining in the message
    int totalVarBytes = 0;
    // Step through each variable
    for (int varIndex = 0; varIndex < variables.size(); varIndex++) {
        // Add the variable's number of bytes to the total
        totalVarBytes += variables.get(varIndex).getSize();
        // Check if this is a bit-wise variable
        if (variables.get(varIndex).getFullName().contains(":")) {
            // Variable's row index in the tree containing all variables
            int treeIndex = allVariableTreePaths.indexOf(variables.get(varIndex).getFullName()) - 1;
            // scheduler table isn't updated then the variable won't be located
            if (treeIndex > -1) {
                // Get the variable's tree node
                ToolTipTreeNode last = (ToolTipTreeNode) allVariableTree.getPathForRow(treeIndex).getLastPathComponent();
                // Get the node indices that encompass the packed variables (if applicable)
                BitPackNodeIndex nodeIndex = allVariableTree.getBitPackedVariables(last);
                // Update the variable index to skip the packed members, if present, so that
                // their bytes don't affect the total
                varIndex += nodeIndex.getLastIndex() - nodeIndex.getFirstIndex();
            }
        }
    }
    return totalVarBytes;
}
Also used : BitPackNodeIndex(CCDD.CcddClassesDataTable.BitPackNodeIndex) ToolTipTreeNode(CCDD.CcddClassesComponent.ToolTipTreeNode)

Example 3 with BitPackNodeIndex

use of CCDD.CcddClassesDataTable.BitPackNodeIndex in project CCDD by nasa.

the class CcddTelemetrySchedulerInput method getAssociatedVariables.

/**
 ********************************************************************************************
 * For the specified list of variables, get (1) the total size in bytes of the variables that
 * are associated with the first variable in the list, and (2) a list of Variable objects of
 * the associated variables. Variables are considered 'associated' if (a) they are all bit-wise
 * variables that are packed together, or (b) they are members of a string. If the first
 * variable isn't associated with the succeeding variables then the return value references
 * only the first variable
 *
 * @param variables
 *            list of variables where the first member of the list if the one to be checked for
 *            associates
 *
 * @return AssociatedVariable object containing the total size in bytes of the variables
 *         associated with the first variable in the specified list and the list of the
 *         associated variables
 ********************************************************************************************
 */
protected AssociatedVariable getAssociatedVariables(List<Variable> variables) {
    // Get a reference to the lead variable. This is the variable that is checked for
    // associated variables
    Variable variable = variables.get(0);
    // Store the size of the variable
    int totalSize = variable.getSize();
    // Create a list to store the lead variable and its associates and add the lead variable to
    // the list
    List<Variable> associatedVars = new ArrayList<Variable>();
    associatedVars.add(variable);
    // Set flag to true if the lead variable is a bit-wise variable
    boolean isBitPack = variable.getFullName().contains(":");
    // variables associated with it)
    if (isBitPack || dataTypeHandler.isString(((TelemetryData) variable).getDataType())) {
        // Get the variable's row index in the tree containing all variables
        int treeIndex = allVariableTreePaths.indexOf(variable.getFullName()) - 1;
        // Get the variable's tree node
        ToolTipTreeNode last = (ToolTipTreeNode) allVariableTree.getPathForRow(treeIndex).getLastPathComponent();
        // Get the indices of the other variables associated with this variable (i.e., other
        // variable bit-packed or other members of the string)
        BitPackNodeIndex nodeIndex = isBitPack ? allVariableTree.getBitPackedVariables(last) : allVariableTree.getStringVariableMembers(last);
        // Calculate the number of other variables associated with the lead variable
        int numVars = nodeIndex.getLastIndex() - nodeIndex.getFirstIndex();
        // in the list provided
        if (numVars <= variables.size()) {
            // Step through the associated variables
            for (int index = 1; index <= numVars; index++) {
                // Check that this isn't a bit-wise variable (i.e, it's a string variable)
                if (!isBitPack) {
                    // Add the variable's size to the total
                    totalSize += variables.get(index).getSize();
                }
                // Add the variable to the list of associated variables
                associatedVars.add(variables.get(index));
            }
        } else // More associated variables were detected than were provided. This can only occur if
        // the rates for associated variables don't match - this shouldn't be possible
        {
            // Inform the user if there is a rate assignment issue
            new CcddDialogHandler().showMessageDialog(schedulerDlg.getDialog(), "<html><b> Auto-fill detected mismatched " + "rates for variable(s) associated with </b>" + variables.get(0).getFullName(), "Assign Failure", JOptionPane.WARNING_MESSAGE, DialogOption.OK_OPTION);
        }
    }
    return new AssociatedVariable(totalSize, associatedVars);
}
Also used : BitPackNodeIndex(CCDD.CcddClassesDataTable.BitPackNodeIndex) AssociatedVariable(CCDD.CcddClassesDataTable.AssociatedVariable) Variable(CCDD.CcddClassesDataTable.Variable) ArrayList(java.util.ArrayList) AssociatedVariable(CCDD.CcddClassesDataTable.AssociatedVariable) TelemetryData(CCDD.CcddClassesDataTable.TelemetryData) ToolTipTreeNode(CCDD.CcddClassesComponent.ToolTipTreeNode)

Example 4 with BitPackNodeIndex

use of CCDD.CcddClassesDataTable.BitPackNodeIndex in project CCDD by nasa.

the class CcddDbTableCommandHandler method updateLinksAndTlmForPackingChange.

/**
 ********************************************************************************************
 * Build the commands to delete variable references in the links and telemetry scheduler tables
 * that are no longer valid due to changes in bit-packing
 *
 * @param parent
 *            reference to the GUI component over which any error dialogs should be centered
 *
 * @return Commands to delete variable references in the links and telemetry scheduler tables
 *         that are no longer valid due to changes in bit-packing
 ********************************************************************************************
 */
private String updateLinksAndTlmForPackingChange(ToolTipTreeNode orgTableNode, Component parent) {
    StringBuilder linksDelCmd = new StringBuilder("");
    StringBuilder tlmDelCmd = new StringBuilder("");
    List<String> removeMembers = new ArrayList<String>();
    List<List<String>> updatedPacking = new ArrayList<List<String>>();
    // Create the table tree after any changes have been applied
    CcddTableTreeHandler tableTree = new CcddTableTreeHandler(ccddMain, TableTreeType.STRUCTURES_WITH_PRIMITIVES, parent);
    // Get the tree node for the updated prototype table
    ToolTipTreeNode updTableNode = tableTree.getNodeByNodeName(orgTableNode.getUserObject().toString());
    // table then in no longer appears in the tree
    if (updTableNode != null) {
        // Step through each variable in the table as it exists after the updates
        for (int childIndex = 0; childIndex < updTableNode.getChildCount(); childIndex++) {
            // Get the indices of all variables bit-packed the variable at the current child
            // index
            BitPackNodeIndex nodeIndex = tableTree.getBitPackedVariables((ToolTipTreeNode) updTableNode.getChildAt(childIndex));
            // Check if any variables are bit-packed with the current variable
            if (nodeIndex.getFirstIndex() != nodeIndex.getLastIndex()) {
                List<String> packMembers = new ArrayList<String>();
                // Step through the bit-packed variables
                for (int packIndex = nodeIndex.getFirstIndex(); packIndex <= nodeIndex.getLastIndex(); packIndex++) {
                    // Add the variable to the pack member list
                    packMembers.add(((ToolTipTreeNode) updTableNode.getChildAt(packIndex)).getUserObject().toString().replaceFirst(":\\d+", ""));
                }
                // Store the pack member list and the individual members
                updatedPacking.add(packMembers);
                removeMembers.addAll(packMembers);
                // Adjust the child index to skip these bit-packed variables
                childIndex = nodeIndex.getLastIndex();
            }
        }
    }
    // Step through each variable in the table as is existed prior to the updates
    for (int childIndex = 0; childIndex < orgTableNode.getChildCount(); childIndex++) {
        // Get the indices of all variables bit-packed the variable at the current child index
        BitPackNodeIndex nodeIndex = tableTree.getBitPackedVariables((ToolTipTreeNode) orgTableNode.getChildAt(childIndex));
        // Check if any variables are bit-packed with the current variable
        if (nodeIndex.getFirstIndex() != nodeIndex.getLastIndex()) {
            List<String> packMembers = new ArrayList<String>();
            // Step through the bit-packed variables
            for (int packIndex = nodeIndex.getFirstIndex(); packIndex <= nodeIndex.getLastIndex(); packIndex++) {
                // Get the variable name minus the bit length
                String variable = ((ToolTipTreeNode) orgTableNode.getChildAt(packIndex)).getUserObject().toString().replaceFirst(":\\d+", "");
                packMembers.add(variable);
                // Check if the individual member list doesn't already contain this variable
                if (!removeMembers.contains(variable)) {
                    // Add the variable to the individual members list
                    removeMembers.add(variable);
                }
            }
            // Step through the list of bit-packed variables in the updated table
            for (List<String> updatedPackMembers : updatedPacking) {
                // the updated table
                if (CcddUtilities.isArraySetsEqual(packMembers.toArray(new String[0]), updatedPackMembers.toArray(new String[0]))) {
                    // Since the bit-packed variables are unchanged, delete them from the list
                    // of variables that are to be removed from the links and telemetry
                    // scheduler tables, and stop searching
                    removeMembers.removeAll(packMembers);
                    break;
                }
            }
            // Adjust the child index to skip these bit-packed variables
            childIndex = nodeIndex.getLastIndex();
        }
    }
    // bit-packed, or packed with different variables)
    for (String variable : removeMembers) {
        // Get the path of the variable
        String packPath = orgTableNode.getUserObject().toString() + "(?:\\\\.[^,]*)?," + CcddUtilities.escapePostgreSQLReservedChars(variable) + "(?::\\\\d+|$)";
        // Delete the variable from the links and telemetry scheduler tables
        deleteLinkPathRef("(?:^|[^,]*,)" + packPath, linksDelCmd);
        deleteTlmPathRef("(?:[^,]+,)*" + packPath, tlmDelCmd);
    }
    return linksDelCmd.toString() + tlmDelCmd.toString();
}
Also used : BitPackNodeIndex(CCDD.CcddClassesDataTable.BitPackNodeIndex) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) ToolTipTreeNode(CCDD.CcddClassesComponent.ToolTipTreeNode)

Example 5 with BitPackNodeIndex

use of CCDD.CcddClassesDataTable.BitPackNodeIndex in project CCDD by nasa.

the class CcddCommonTreeHandler method getBitPackedVariables.

/**
 ********************************************************************************************
 * Determine the node indices in the table tree that encompass a group of bit-packed variables
 *
 * @param node
 *            selected node for a (potentially) bit-packed variable
 *
 * @return NodeIndex object containing the node indices bounding the bit-packed variables
 ********************************************************************************************
 */
protected BitPackNodeIndex getBitPackedVariables(ToolTipTreeNode node) {
    // Get the variable name from the node
    String varName = removeExtraText(node.getUserObject().toString());
    // Get the corresponding node in the variable tree
    ToolTipTreeNode tblParent = (ToolTipTreeNode) node.getParent();
    // Get this variable tree node's index in the variable tree relative to its parent node
    int tblIndex = tblParent.getIndex(node);
    int firstIndex = tblIndex;
    int lastIndex = tblIndex;
    // Check if the target variable has a bit length
    if (varName.contains(":")) {
        // Get the data type for this variable and calculate the number of bits it occupies
        String dataType = varName.substring(0, varName.indexOf("."));
        int dataTypeBitSize = dataTypeHandler.getSizeInBits(dataType);
        // Set the current index in preparation for locating other variables packed with this
        // one. Note that this can result is stepping backwards into another pack; this is
        // accounted for further down
        int curIndex = tblIndex - 1;
        // data type are found
        while (curIndex >= 0) {
            // Get the variable name from the node
            varName = removeExtraText(((ToolTipTreeNode) tblParent.getChildAt(curIndex)).getUserObject().toString());
            // the target
            if (!varName.contains(":") || !varName.startsWith(dataType + ".")) {
                // Stop searching
                break;
            }
            curIndex--;
        }
        // Adjust the index and save this as the starting index, and store its associated tree
        // node index
        curIndex++;
        firstIndex = curIndex;
        int bitCount = 0;
        boolean isTargetInPack = false;
        // variable's pack
        while (curIndex < node.getSiblingCount()) {
            // Get the variable name from the node
            varName = removeExtraText(((ToolTipTreeNode) tblParent.getChildAt(curIndex)).getUserObject().toString());
            // the target
            if (!varName.contains(":") || !varName.startsWith(dataType + ".")) {
                // Check if the target variable is a member of this packed group
                if (curIndex == tblIndex) {
                    // Set the flag indicating this pack includes the target variable
                    isTargetInPack = true;
                }
                // Stop searching
                break;
            }
            // Add the number of bits occupied by this variable to the running count
            int bitLength = Integer.valueOf(macroHandler.getMacroExpansion(varName.substring(varName.indexOf(":") + 1)));
            bitCount += bitLength;
            // Check if the bit count rolled over the maximum allowed
            if (bitCount > dataTypeBitSize) {
                // Check if the target variable is included in the range of packed variables
                if (isTargetInPack) {
                    // stop searching
                    break;
                }
                // Reset the bit count to the current row's value and store the row index for
                // the first variable in the pack. This accounts for one or more bit-wise
                // variables occurring immediately prior to the pack containing the target
                bitCount = bitLength;
                firstIndex = curIndex;
            }
            // Check if the target variable is a member of this packed group
            if (curIndex == tblIndex) {
                // Set the flag indicating this pack includes the target variable
                isTargetInPack = true;
            }
            curIndex++;
        }
        // Store the last index in the pack. If the variable isn't bit-packed (i.e., has no bit
        // length or has no other pack members) then the last index is the same as the first
        // index
        lastIndex = curIndex - (isTargetInPack ? 1 : 0);
    }
    return new BitPackNodeIndex(firstIndex, lastIndex, tblIndex);
}
Also used : BitPackNodeIndex(CCDD.CcddClassesDataTable.BitPackNodeIndex) ToolTipTreeNode(CCDD.CcddClassesComponent.ToolTipTreeNode)

Aggregations

BitPackNodeIndex (CCDD.CcddClassesDataTable.BitPackNodeIndex)7 ToolTipTreeNode (CCDD.CcddClassesComponent.ToolTipTreeNode)6 ArrayList (java.util.ArrayList)2 AssociatedVariable (CCDD.CcddClassesDataTable.AssociatedVariable)1 TelemetryData (CCDD.CcddClassesDataTable.TelemetryData)1 Variable (CCDD.CcddClassesDataTable.Variable)1 List (java.util.List)1 Icon (javax.swing.Icon)1 ImageIcon (javax.swing.ImageIcon)1