Search in sources :

Example 1 with AssociatedVariable

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

the class CcddSchedulerHandler method autoFill.

/**
 ********************************************************************************************
 * Automatically fill the variables/applications in messages/time slots corresponding to their
 * rate
 ********************************************************************************************
 */
protected void autoFill() {
    canceled = false;
    cancelDialog = new HaltDialog();
    progBar = new JProgressBar();
    progress = 0;
    // Create the panel to contain the progress/cancellation dialog components
    final JPanel dialogPnl = new JPanel(new GridBagLayout());
    // Get the scheduler dialog type
    final SchedulerType schedulerType = getSchedulerOption();
    // Get the text that describes the type of object being assigned
    final String variableType = schedulerType == SchedulerType.TELEMETRY_SCHEDULER ? "variables" : (schedulerType == SchedulerType.APPLICATION_SCHEDULER ? "applications" : "unknown");
    // Create a thread to perform the auto-fill operation in the background
    final Thread progressThread = new Thread(new Runnable() {

        /**
         ************************************************************************************
         * Auto-fill the telemetry messages (if this is the telemetry scheduler) or application
         * time slots (if this is the application scheduler). Note that in the comments below
         * 'variable' is used to describe the object being assigned, which is accurate for the
         * telemetry scheduler. For the application scheduler substitute 'application' for
         * 'variable'
         ************************************************************************************
         */
        @Override
        public void run() {
            int numVariables = 0;
            int unassigned = 0;
            // Get an array of the available rates
            String[] availableRates = schedulerInput.getAvailableRates();
            // variables at each rate until no more rates are available
            for (String rate : availableRates) {
                // out using HTML tags
                if (!rate.startsWith("<html>")) {
                    // Check if this is a telemetry scheduler
                    if (schedulerType == SchedulerType.TELEMETRY_SCHEDULER) {
                        // Get the reference to the variable tree in order to shorten the
                        // subsequent call
                        CcddTableTreeHandler variableTree = ((CcddTelemetrySchedulerInput) schedulerInput).getVariableTree();
                        // Add the number of unassigned variables at the given rate.
                        // getVariablesAtRate() could be used, but it performs other operations
                        // associated with links and is slower
                        numVariables += variableTree.getPrimitiveVariablePaths(variableTree.getRootNode(), true).size();
                    } else // Check if this is an application scheduler
                    if (schedulerType == SchedulerType.APPLICATION_SCHEDULER) {
                        // Add the number of unassigned applications at the given rate
                        numVariables += schedulerInput.getVariablesAtRate(rate).size();
                    }
                }
            }
            // Check if there are any variables to assign
            if (numVariables != 0) {
                // Update the progress bar now that the number of variables is known
                progBar.setMaximum(numVariables);
                progBar.setIndeterminate(false);
                // Total size of the variable or link
                int totalSize;
                // Message option to which the variable or link will be added
                String option;
                // Variable that will be added
                Variable variable;
                // Variables that will be removed from the remaining list
                List<Variable> removedVars = new ArrayList<Variable>();
                // List of variables at a given rate
                List<Variable> varList;
                // List of the variables to exclude from the Variables tree. This should be all
                // of the variables unless there are any that can't be assigned
                List<String> excludedVars = new ArrayList<String>();
                // variables at each rate until no more rates are available
                for (String rate : availableRates) {
                    // Check if the user canceled auto-fill
                    if (canceled) {
                        break;
                    }
                    // grayed out using HTML tags
                    if (!rate.startsWith("<html>")) {
                        // Show the current rate being processed in the progress bar
                        progBar.setString("Assigning " + rate + " Hz " + variableType);
                        // Get the rate as a floating point value
                        float rateVal = CcddUtilities.convertStringToFloat(rate);
                        // Get a list of all variables at the given rate (ones already assigned
                        // are not included)
                        varList = schedulerInput.getVariablesAtRate(rate);
                        // Sort the list from largest to smallest
                        Collections.sort(varList);
                        // Loop through the list of variables until all are removed
                        while (!varList.isEmpty()) {
                            // Check if the user canceled padding adjustment
                            if (canceled) {
                                break;
                            }
                            // Total size of the variable or link
                            totalSize = 0;
                            // Set to the first variable in the list
                            variable = varList.get(0);
                            // Check if the variable is linked
                            if (variable.getLink() != null) {
                                // Step through each variable in the variable list
                                for (Variable linkVar : varList) {
                                    // variable
                                    if (linkVar.getLink() != null && linkVar.getLink().equals(variable.getLink())) {
                                        // Add the variable's size to the total size
                                        totalSize += variable.getSize();
                                        // Add the variable to the list of removed variables
                                        removedVars.add(linkVar);
                                    }
                                }
                            } else // The variable is unlinked
                            {
                                // Check if this is a telemetry scheduler
                                if (schedulerType == SchedulerType.TELEMETRY_SCHEDULER) {
                                    // Set total size to the given variable's size
                                    totalSize = variable.getSize();
                                    // Get the total size (in bytes) and the list of the
                                    // variable, or variables if this variable is associated
                                    // with others due to bit-packing or string membership and
                                    // therefore must be placed together in a message
                                    AssociatedVariable associates = ((CcddTelemetrySchedulerInput) schedulerInput).getAssociatedVariables(varList);
                                    // Set the total size to that of the associated variable(s)
                                    // and add the variable(s) to the list of those to be
                                    // removed
                                    totalSize = associates.getTotalSize();
                                    removedVars.addAll(associates.getAssociates());
                                } else // This is an application (or unknown type of) scheduler
                                {
                                    // Set total size to the given variable's size
                                    totalSize = variable.getSize();
                                    // Add the variable to the list of removed variables
                                    removedVars.add(variable);
                                }
                            }
                            // Find the option with the most room
                            option = getMessageWithRoom(rateVal, totalSize);
                            // Check to make sure there is an option
                            if (option != null) {
                                // Parse the option string to extract the sub-index (if this is
                                // a sub-option) and the message indices
                                Object[] parsedIndices = parseOption(option);
                                // Add the variable to the given message. If a sub-index is not
                                // given it will be set to -1. Add the list of added variables
                                // to the list of those to exclude in the Variables tree
                                excludedVars.addAll(addVariableToMessage(removedVars, (Integer[]) parsedIndices[1], (int) parsedIndices[0]));
                            } else // No option is available
                            {
                                // Increment the unplaced variable counter
                                unassigned++;
                            }
                            // Remove all the variables in removed variables list. This
                            // includes variables that did not fit into the telemetry table
                            varList.removeAll(removedVars);
                            // Clear the removed variables list
                            removedVars.clear();
                            // Update the auto-fill progress
                            progBar.setValue(progress);
                            progress++;
                        }
                    }
                }
                // Check if the auto-fill operation wasn't canceled by the user
                if (!canceled) {
                    // Close the auto-fill progress/cancellation dialog
                    cancelDialog.closeDialog(CANCEL_BUTTON);
                }
                // Perform any updates needed following adding variables to messages
                updateAfterVariableAdded();
                // Set the variable tree to exclude the variable(s)
                setVariableUnavailable(excludedVars);
                // Display the originally selected rate's variable tree
                schedulerInput.updateVariableTree(rateFilter.getSelectedItem().toString());
                // Update the remaining bytes column values
                schedulerEditor.updateRemainingBytesColumn();
                // Update the unused bytes/time field
                setUnusedField();
                // Update the assigned variables/applications list panel
                schedulerEditor.updateAssignmentList();
                // Update the scheduler dialog's change indicator
                getSchedulerDialog().updateChangeIndicator();
                // Check if there are items that are not assigned
                if (unassigned != 0) {
                    // Inform the user if there are items that are not assigned
                    new CcddDialogHandler().showMessageDialog(schedulerDlg.getDialog(), "<html><b> Auto-fill unable to assign " + unassigned + " " + variableType, "Auto-fill", JOptionPane.WARNING_MESSAGE, DialogOption.OK_OPTION);
                }
            } else // There are no unassigned variables
            {
                // user
                if (!canceled) {
                    // Close the auto-fill progress/cancellation dialog
                    cancelDialog.closeDialog(CANCEL_BUTTON);
                }
                new CcddDialogHandler().showMessageDialog(schedulerDlg.getDialog(), "<html><b>All " + variableType + " with a rate are already assigned", "Auto-fill", JOptionPane.INFORMATION_MESSAGE, DialogOption.OK_OPTION);
            }
        }
    });
    // Execute the command in the background
    CcddBackgroundCommand.executeInBackground(ccddMain, schedulerDlg.getDialog(), new BackgroundCommand() {

        /**
         ************************************************************************************
         * Build and display the auto-fill progress/cancellation dialog. This is done as a
         * background operation so that the
         ************************************************************************************
         */
        @Override
        protected void execute() {
            // Set the initial layout manager characteristics
            GridBagConstraints gbc = new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2, ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing(), 0, ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing()), 0, 0);
            // Build the progress/cancellation dialog
            dialogPnl.setBorder(BorderFactory.createEmptyBorder());
            JLabel textLbl = new JLabel("<html><b>Assigning " + variableType + "...</b><br><br>", SwingConstants.LEFT);
            textLbl.setFont(ModifiableFontInfo.LABEL_PLAIN.getFont());
            gbc.gridy++;
            dialogPnl.add(textLbl, gbc);
            JLabel textLbl2 = new JLabel("<html><b>" + CcddUtilities.colorHTMLText("*** Press </i>Halt<i> " + "to terminate auto-fill ***", Color.RED) + "</b><br><br>", SwingConstants.CENTER);
            textLbl2.setFont(ModifiableFontInfo.LABEL_PLAIN.getFont());
            gbc.gridy++;
            dialogPnl.add(textLbl2, gbc);
            // Add a progress bar to the dialog
            progBar.setIndeterminate(true);
            progBar.setMinimum(0);
            progBar.setValue(0);
            progBar.setString("Calculating number of variables");
            progBar.setStringPainted(true);
            progBar.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
            gbc.insets.left = ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing() * 2;
            gbc.insets.right = ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing() * 2;
            gbc.insets.bottom = 0;
            gbc.gridy++;
            dialogPnl.add(progBar, gbc);
            // the dialog if there are no variables to assign
            if (!canceled) {
                // Display the auto-fill progress/cancellation dialog
                cancelDialog.showOptionsDialog(schedulerDlg.getDialog(), dialogPnl, "Auto-fill " + (schedulerType == SchedulerType.TELEMETRY_SCHEDULER ? "Telemetry Messages" : (schedulerType == SchedulerType.APPLICATION_SCHEDULER ? "Time Slots" : "")), DialogOption.HALT_OPTION, false, true);
            }
        }
    });
    // Perform the auto-fill operation in a background thread
    progressThread.start();
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) AssociatedVariable(CCDD.CcddClassesDataTable.AssociatedVariable) Variable(CCDD.CcddClassesDataTable.Variable) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) JProgressBar(javax.swing.JProgressBar) AssociatedVariable(CCDD.CcddClassesDataTable.AssociatedVariable) JLabel(javax.swing.JLabel) SchedulerType(CCDD.CcddConstants.SchedulerType) ArrayList(java.util.ArrayList) JList(javax.swing.JList) List(java.util.List) BackgroundCommand(CCDD.CcddBackgroundCommand.BackgroundCommand)

Example 2 with AssociatedVariable

use of CCDD.CcddClassesDataTable.AssociatedVariable 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)

Aggregations

AssociatedVariable (CCDD.CcddClassesDataTable.AssociatedVariable)2 Variable (CCDD.CcddClassesDataTable.Variable)2 ArrayList (java.util.ArrayList)2 BackgroundCommand (CCDD.CcddBackgroundCommand.BackgroundCommand)1 ToolTipTreeNode (CCDD.CcddClassesComponent.ToolTipTreeNode)1 BitPackNodeIndex (CCDD.CcddClassesDataTable.BitPackNodeIndex)1 TelemetryData (CCDD.CcddClassesDataTable.TelemetryData)1 SchedulerType (CCDD.CcddConstants.SchedulerType)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 Insets (java.awt.Insets)1 List (java.util.List)1 JLabel (javax.swing.JLabel)1 JList (javax.swing.JList)1 JPanel (javax.swing.JPanel)1 JProgressBar (javax.swing.JProgressBar)1