Adding Conditions to the Assistant

Add a post-condition to Task 1 and a pre-condition to Task 2.

In a Simulation Assistant, conditions impose requirements that must be met at specific points in the workflow. There are two types of conditions:
  • Pre-conditions—define what is required before a task can begin.
  • Post-conditions—check that the requirements of a task are met.

In this tutorial, you add a post-condition to Task 1, and a pre-condition to Task 2. The condition checks whether a geometry file part exists in the simulation. If no part exists, Task 1 is not complete and Task 2 is disabled.

It is good practice to add the code for all conditions in a separate class:

  1. Add a new class to the Assistant package and name it InternalFlowConditions.


  2. Copy the following code into the InternalFlowConditions class. Comments are included in the code:
    package Assistant;
    
    import java.util.Collections;
    import star.assistant.CSOCondition;
    import star.assistant.CSOLookupConditionTrigger;
    import star.common.GeometryPart;
    import star.common.filters.Predicate;
    
    /**
     * This class contains all conditions used in the Internal Flow Assistant.
     */
    public class InternalFlowConditions {
    
        public static synchronized CSOCondition<GeometryPart> createPartCondition() {
    
            // Creates a new condition
            CSOCondition<GeometryPart> partCondition = new CSOCondition<GeometryPart>();
            // Sets the text description of the condition
            partCondition.setDesc("A geometry part must be present.");
            // Creates a new condition trigger that goes off when a cadpart is added to the lookup
            CSOLookupConditionTrigger<GeometryPart> partConditionTrigger = new CSOLookupConditionTrigger<GeometryPart>(GeometryPart.class);
            // Sets the list of triggers to the one created above.
            partCondition.setTriggers(Collections.singleton(partConditionTrigger));
            // Creates a new predicate (true/false evaluation) with an evaluate method and evaluates whether an object satisfies the condition.
            partCondition.setPredicate(new Predicate<GeometryPart>() {
                @Override
                public boolean evaluate(GeometryPart part) {
                    // You could check for specific attributes of the part here.
                    return true;
                }
            });
            return partCondition;
        }
    }