Implement New Commands For <WorkItemNode>

NOTE: This exercise assumes you have completed the previous exercise.

As part of our original design, we took note that it was important to address quality of life features. In this exercise you'll learn to implement Scenome application commands that form an integral part of the user experience. The first command allows you to toggle the debug state of the <WorkItemNode> so you can test and debug workloads, and the second command allows you to disable the <WorkItemNode> so that it won't be processed at all. The new commands are simple, but they make it much easier to get work done.

Implement The ToggleDebug Algorithm

  1. Return to the running text editor and find the file type_work_item_node_algorithms.ssl.

    ///////////////////////////////////////////////////////////////////////////////
    //
    // $author           Scenomics LLC
    // $description      Implements algorithms for WorkItemNode.
    //
    // Copyright 2004-2023 Scenomics LLC. All Rights Reserved.
    //
    ///////////////////////////////////////////////////////////////////////////////
    
    library LibWorkItemNodeAlgorithms;
    
    import library "type_service_enumeration_util.ssl";
    import library "app_service_console_util.ssl";
    import library "app_service_message_box_util.ssl";
    import library "type_work_item_node_util.ssl";
    
  2. Insert the following function immediately below the import statements.

    Copy Text To Clipboard

    ///////////////////////////////////////////////////////////////////////////////
    // function
    ///////////////////////////////////////////////////////////////////////////////
    
    function bool ToggleDebug( NodeBuffer p_apNodes )
    {
       for( int i = 0; i < p_apNodes.GetCount(); ++i )
       {
          WorkItemNode a_oNode = (WorkItemNode)p_apNodes.Get( i );
          a_oNode.Debug = !a_oNode.Debug;
       }
    
       return true;
    }
    

    This algorithm is simple and easy to understand. It iterates over a collection of <WorkItemNodes> and toggles the Debug flag. If the flag is true, it becomes false and vice versa. Generally, in Scenome Scripting Language libraries, we like to keep simple loops out of macro code. This isn't a hard and fast rule, but it helps keep the macro code readable. The <WorkItemNode> macro library will just have a single call to this library, and won't need to contain the loop iteration code.

  3. Save the script with the text editor.

Implement The ToggleDebug Macro

  1. Return to the running text editor and find the file type_work_item_node_scripts.ssl.

    ///////////////////////////////////////////////////////////////////////////////
    //
    // $author           Scenomics LLC
    // $description      Implements commands for WorkItemNode.
    //
    // Copyright 2004-2023 Scenomics LLC. All Rights Reserved.
    //
    ///////////////////////////////////////////////////////////////////////////////
    
    [Package="Scenome-Package-Project"]
    
    import library "app_service_assert_util.ssl";
    import library "app_service_console_util.ssl";
    import library "app_service_message_box_util.ssl";
    import library "type_work_item_node_algorithms.ssl";
    
    ///////////////////////////////////////////////////////////////////////////////
    // macro
    ///////////////////////////////////////////////////////////////////////////////
    
    function void WorkItemNodeCommand_OnUpdate( CommandPresentationModuleInfo commandInfo )
    {
       ValidateNodeCommandContext.TestSelection( commandInfo, WorkItemNode, 1, true,
          "This command..." );
    }
    
    macro WorkItemNodeCommand()
    [Category="WorkItemNode Commands", Package="Scenome-Package-Project", Guid="{AB4A7F29-3197-481A-9B4B-10455AE45AE9}", Image=".\\icons\\generic_script_icon.bmp"]
    {
       // Do something here...
    }
    
  2. Replace the entire code block that implements the macro with the following code.

    Copy Text To Clipboard

    ///////////////////////////////////////////////////////////////////////////////
    // macro
    ///////////////////////////////////////////////////////////////////////////////
    
    function void WorkItemNodeToggleDebug_OnUpdate( CommandPresentationModuleInfo commandInfo )
    {
       ValidateNodeCommandContext.TestSelection( commandInfo, WorkItemNode, -1, true,
          "Toggles the <WorkItemNode> debug flag" );
    }
    
    macro WorkItemNodeToggleDebug()
    [Category="WorkItemNode Commands", Package="Scenome-Package-Project", Guid="{AB4A7F29-3197-481A-9B4B-10455AE45AE9}", Image=".\\icons\\generic_script_icon.bmp"]
    {
       auto NodeBuffer nodes = LibSelection.EditSelected( Node );
       LibWorkItemNodeAlgorithms.ToggleDebug( nodes );
    }
    

    This macro is very simple. The function WorkItemNodeToggleDebug_OnUpdate ensures that the command is only active if some number of <WorkItemNode> objects are selected. This function implements the command presentation policy, which determines whether the command is grayed out or if it can be executed.

    Then, in the implementation, the line auto NodeBuffer nodes = LibSelection.EditSelected( Node ); populates a <NodeBuffer> object with all the selected nodes. It's important to know that calling LibSelection.EditSelected( Node ) means that the node objects will be in a memento state, which means that we will be unable to undo our changes.

    We know all the nodes in the <NodeBuffer> named nodes will all be of type <WorkItemNode> because otherwise the command cannot be executed, per the command presentation policy specified in the function WorkItemNodeToggleDebug_OnUpdate.

    Finally, we call the algorithm that toggles the debug flag.

  3. Save the script with the text editor.

Add The Command To The <WorkItemNode> Context Menu

  1. Return to the Shell app containing WorkGroupNode ( Standard ) Context Menu.box.
  2. Select Desktop » Refresh Scripts.
  3. Select File » Open from the main menu.

    The software presents a dialog that allows you to choose which file to open.

  4. Type WorkItemNode ( Standard ) Context Menu.box and click Open or hit ENTER when you are finished.

    Copy Text To Clipboard

    WorkItemNode ( Standard ) Context Menu.box
    This is a picture of the hierarchy.
  5. Right click over the <ContextMenuElementnode> named WorkItemNode and select Create Command Item From GUID... from the listed options.

    The software displays a text entry dialog that allows you to enter a Scenome command macro GUID. This is a picture of the text entry dialog asking for a GUID.

  6. Copy {AB4A7F29-3197-481A-9B4B-10455AE45AE9} in the dialog and click OK or hit ENTER when you are finished.

    Copy Text To Clipboard

    {AB4A7F29-3197-481A-9B4B-10455AE45AE9}

    The dialog appears again in case we wish to enter another GUID. This is a picture of the text entry dialog asking for a GUID.

  7. Click OK or hit ENTER to dismiss the dialog without entering another GUID.

    The software creates a new <ItemElementNode> named WorkItemNodeToggleDebug and places it at the end of the list of menu items. This is the new Scenome command macro!

    This is a picture of the hierarchy.
  8. Right click over the new <ItemElementNode> named WorkItemNodeToggleDebug and select Rename... from the listed options.

    The software displays a dialog box that allows you to rename the node.

    This is a picture of the rename dialog.
  9. Type &amp;Toggle Debug and click OK or hit ENTER when you are finished.

    Copy Text To Clipboard

    &amp;Toggle Debug

    The software renames the node. Using &amp; before T sets the accelerator key to T, which means you can hit T when this menu is visible to execute this command.

    This is a picture of the hierarchy.
  10. Select Graph » Move » Move To Top from the main menu.

    This moves the node to the top of the list of menu items.

    This is a picture of the hierarchy.
  11. Right click over the <ContextMenuElementnode> named WorkItemNode and select Create Command Item From GUID... from the listed options.

    The software displays a text entry dialog that allows you to enter a Scenome command macro GUID. This is a picture of the text entry dialog asking for a GUID.

  12. Copy {1F91F995-F612-46D4-A453-4B81096121A9} in the dialog and click OK or hit ENTER when you are finished.

    Copy Text To Clipboard

    {1F91F995-F612-46D4-A453-4B81096121A9}

    The dialog appears again in case we wish to enter another GUID. This is a picture of the text entry dialog asking for a GUID.

  13. Click OK or hit ENTER to dismiss the dialog without entering another GUID.

    The software creates a new <ItemElementNode> named ToggleVisible and places it at the end of the list of menu items.

    This is a picture of the hierarchy.
  14. Right click over the new <ItemElementNode> named ToggleVisible and select Rename... from the listed options.

    The software displays a dialog box that allows you to rename the node.

    This is a picture of the rename dialog.
  15. Type &amp;Visible and click OK or hit ENTER when you are finished.

    Copy Text To Clipboard

    Toggle &amp;Visible

    The software renames the node. Using &amp; before V sets the accelerator key to V, which means you can hit V when this menu is visible to execute this command.

    This is a picture of the hierarchy.
  16. Select Graph » Move » Move To Top from the main menu.

    This moves the node to the top of the list of menu items.

    This is a picture of the hierarchy.
  17. Select File » Save from the main menu.

Verify Changes

  1. Return to the Shell app containing Octopus.box.
  2. Select Graph » Build All from the main menu.

    The software rebuilds the Octopus app.

  3. Examine the hierarchy and find the <ApplicationConfigNode> named Interface. This is a picture of the hierarchy.
  4. Right click over the <ApplicationConfigNode> named Interface and select Run Application from the listed options.

    The Octopus splash screen appears and the application starts.

  5. Select File » Open from the main menu.

    You're inside the Octopus library directory.

  6. Enter the folder named Western-Washington-Mt-Baker-Terrain-Analysis.
  7. Open the file named Western-Washington-Mt-Baker-Terrain-Analysis.box. This is a picture of the hierarchy.
  8. Right click on the <WorkItemNode> named BuildArrayTextureFromGeotiff. This is a picture of the hierarchy.

    You can see the new commands Toggle Visible and Toggle Debug. You can try them if you want. If you do, you'll notice the icons change, and that you can undo the changes.

  9. Return to the running Shell application that contains WorkItemNode ( Standard ) Context Menu.box.
  10. Select File » Exit from the main menu.

    This exercise is complete. Please proceed to the next exercise.