Table of Contents

Mission Panel

The Mission Panel manages NC program loading, editing, and preparation for simulation in the geometry-only HiNC application.

Panel Layout

  • Left side: NC Program Management Panel

    • Program Files Section
      • Load NC File button
      • New NC File button
      • List view of loaded NC programs
      • Remove button (to remove selected program)
    • Program Properties Section
      • File name and path display
      • Program description input field
      • Program size and line count display
    • Program Association Section
      • Tool mapping controls:
        • Dropdown to select T-code
        • Dropdown to select corresponding tool from Tool House
        • Apply Mapping button
      • Work offset mapping controls:
        • Dropdown to select work offset code (G54, G55, etc.)
        • X, Y, Z offset value inputs
        • Apply Offset button
  • Right side: NC Program Editor/Viewer

    • Syntax-highlighted G-code editor
    • Line numbers
    • Save button
    • Validate button
    • Validation results display area
    • Show Toolpath Preview toggle button
  • Bottom: Toolpath Preview Panel (shown when preview is toggled on)

    • 3D view of the toolpath
    • Color-coded display based on operation type or feed rate
    • Basic camera controls

Behavior

Loading NC Program Files

When the user clicks the Load NC File button:

  1. Open a file selection dialog showing NC files (*.nc, *.cnc, *.ngc, etc.)
  2. After selection, validate the file format
  3. Add the file to the list of NC programs
  4. Display the file in the editor/viewer
  5. Update program properties display
// Example code
public void LoadNCFile(string filePath)
{
    if (File.Exists(filePath))
    {
        // Read and validate NC file
        string programContent = File.ReadAllText(filePath);
        
        // Create a new program object
        NCProgram program = new NCProgram
        {
            FilePath = filePath,
            FileName = Path.GetFileName(filePath),
            Content = programContent,
            LineCount = programContent.Split('\n').Length,
            FileSize = new FileInfo(filePath).Length
        };
        
        // Add to the project's mission
        machiningProject.MachiningMission.Programs.Add(program);
        
        // Update the NC program list view
        UpdateProgramListView();
        
        // Select the newly added program
        SelectProgram(program);
        
        // Display the program in the editor
        LoadProgramIntoEditor(program);
    }
}

Creating a New NC Program

When the user clicks the New NC File button:

  1. Create a new empty NC program object
  2. Add it to the list of programs
  3. Load it into the editor with minimal template content
  4. Allow the user to start editing
public void CreateNewNCProgram()
{
    // Create a basic template for a new NC program
    string templateContent = "%\nO0001\n(NEW PROGRAM)\n\nG90 G40 G17\nG21 (MM)\n\n(PROGRAM BODY)\n\nM30\n%";
    
    // Create a new program object
    NCProgram program = new NCProgram
    {
        FileName = "NewProgram.nc",
        Content = templateContent,
        LineCount = templateContent.Split('\n').Length,
        IsNew = true
    };
    
    // Add to the project's mission
    machiningProject.MachiningMission.Programs.Add(program);
    
    // Update the NC program list view
    UpdateProgramListView();
    
    // Select the newly added program
    SelectProgram(program);
    
    // Display the program in the editor
    LoadProgramIntoEditor(program);
}

Tool Mapping

When the user sets up a tool mapping and clicks Apply Mapping:

  1. Extract the T-code from the selected dropdown
  2. Get the corresponding tool from the Tool House based on the selection
  3. Add or update the mapping in the mission's tool map
  4. Update the display to show the active mapping
public void ApplyToolMapping(string tCodeStr, int toolHousePosition)
{
    if (int.TryParse(tCodeStr.Substring(1), out int tCode))
    {
        // Get the tool from the tool house
        var tool = machiningProject.MachiningToolHouse[toolHousePosition];
        if (tool != null)
        {
            // Update or add the mapping
            machiningProject.MachiningMission.ToolMap[tCode] = toolHousePosition;
            
            // Update the display
            UpdateToolMappingDisplay();
        }
    }
}

Work Offset Mapping

When the user sets up a work offset and clicks Apply Offset:

  1. Extract the offset code (G54, G55, etc.)
  2. Create a vector from the X, Y, Z input values
  3. Add or update the offset in the mission's work offset map
  4. Update the display to show the active offset
public void ApplyWorkOffset(string offsetCode, double x, double y, double z)
{
    // Create the offset vector
    Vec3d offset = new Vec3d(x, y, z);
    
    // Update or add the mapping
    machiningProject.MachiningMission.WorkOffsetMap[offsetCode] = offset;
    
    // Update the display
    UpdateWorkOffsetDisplay();
}

Validating NC Program

When the user clicks the Validate button:

  1. Parse the current program content in the editor
  2. Check for syntax errors
  3. Verify tool references against the tool map
  4. Check for unsupported G/M codes
  5. Display validation results in the results area
public void ValidateProgram()
{
    // Get the current content from the editor
    string programContent = GetEditorContent();
    
    // Create a validator
    NCProgramValidator validator = new NCProgramValidator(machiningProject);
    
    // Perform validation
    ValidationResult result = validator.Validate(programContent);
    
    // Display results
    ClearValidationResultsDisplay();
    if (result.IsValid)
    {
        DisplayValidationSuccess("Program validation successful.");
    }
    else
    {
        foreach (var error in result.Errors)
        {
            DisplayValidationError(error);
        }
    }
}

Displaying Toolpath Preview

When the user toggles the Show Toolpath Preview:

  1. If toggled on: a. Parse the NC program b. Generate a toolpath using the geometry-only simulation engine c. Render the toolpath in the preview panel d. Show the preview panel
  2. If toggled off: a. Hide the preview panel
public void ToggleToolpathPreview(bool showPreview)
{
    if (showPreview)
    {
        // Get the current program
        NCProgram program = GetSelectedProgram();
        
        // Generate toolpath (simplified for geometry-only)
        Toolpath toolpath = ToolpathGenerator.GenerateFromNCProgram(
            program.Content, 
            machiningProject.MachiningMission.ToolMap,
            machiningProject.MachiningMission.WorkOffsetMap,
            machiningProject.MachiningEquipment);
        
        // Render the toolpath
        RenderToolpathPreview(toolpath);
        
        // Show the preview panel
        toolpathPreviewPanel.Visibility = Visibility.Visible;
    }
    else
    {
        // Hide the preview panel
        toolpathPreviewPanel.Visibility = Visibility.Collapsed;
    }
}

Data Structure

The panel operates primarily on the MachiningMission of the MachiningProject:

public class MachiningMission
{
    public List<NCProgram> Programs { get; set; } = new List<NCProgram>();
    public Dictionary<int, int> ToolMap { get; set; } = new Dictionary<int, int>();
    public Dictionary<string, Vec3d> WorkOffsetMap { get; set; } = new Dictionary<string, Vec3d>();
    // Other mission-related properties
}

public class NCProgram
{
    public string FilePath { get; set; }
    public string FileName { get; set; }
    public string Content { get; set; }
    public long FileSize { get; set; }
    public int LineCount { get; set; }
    public bool IsNew { get; set; }
    public string Description { get; set; }
    // Other program-related properties
}

Integration with Main Application

The Mission Panel is activated when the user selects the Mission item in the Navigation Menu. It accesses and modifies the MachiningMission component of the current MachiningProject instance.

When changes are made in this panel, the following notifications should be sent:

  1. ProgramListChanged - When programs are added or removed
  2. ProgramContentChanged - When program content is edited
  3. ToolMapChanged - When tool mappings are updated
  4. WorkOffsetMapChanged - When work offsets are updated

These notifications allow other components (particularly the Player panel) to update their behavior accordingly when preparing for or executing the simulation.