Triggers - HiStructClient/femcad-doc GitHub Wiki

Triggers

Triggers are used to control particular action and initiate another action if necessary. The aim of this is to not allow unreasonable input, for example, by controlling related input values. Each trigger has got certain condition which evokes or not certain action. The trigger is performed when the Condition has value False.

trigger_constraint = {
   Variable = variable to be affected,
   VariableScope = "global" | "local" | "fromconstraint",   # optional parameter, defines whether the variable is local or global
   Condition = bool,
   Init = variable to be initialized,
   Explanation = text displayed
}

Triggers can be combined and merged, we can thus activate more triggers at one user action. Here's an axemple of InputItemAction button with set of triggers:

GoClimbing = res.fit.InputItemAction{
   NameSpace            = NameSpace + "GoClimbing.",
   Description          = "",
   HmtlContent          = " Go climbing! ",
   EditabilityCondition = True,
   CssStyleClass        = "fcs-parameterItem-inMenuButton",
   ActionName           = "building.activities.GoClimbing_Trigger",
   ValidationTrigger    = "building.activities.GoClimbing_Trigger",
}

GoClimbing_Trigger = {
   Constraints = (
      [ 
        [ # first run
           TakeRopeConstraint,
           TakeHelmetConstraint,
           ForcePartnerToGoConstraint,
        ],
        [ # second run
           Action.DriveToTheRocks{TakenEquipmentClass}
        ] 
      ]
   )
}

Notice that constraints are divided to 2 groups, at first, group 1 is solved, then values from first group are used in calculation of second group. If you want HiStruct to activate constraints one-by-one (so the constraint value is calculated depending on the previous constraint), leave all the constraints in one array:

MakeDinner_Trigger = {
   Constraints = [
      PrepareDishesBasedOnNumberOfPeople,
      AskHowHungryTheyAre,
      CookTheDinnerBasedOnNumberOfPeopleAndHungerMagnitude,
   ]
}

Note:

  • if the trigger is linked to an input item (integer, double, string, ..), the user input is applied before evaluation of constraints
  • constraints can modify only values referenced by any input item. If you need to update any other value you need to create a hidden input item for it
  • top level of Constraints array needs to be an actuall array, not a variable represeted by a string
  • Constraints array may contain standard constraint represented by dynamic object, or an array, or variable represeted by a string leading to a constrain object or array of constraints.
  • only the first level of Constraints array rules the individual evaluation

Global trigger with instance indexes

With nested input types inside of the model, there might be a need for HiStruct driven action on different input item (type) object.

   ValidationTrigger = (
      "<site.construct.silos.inputs[%item]>site.construct.siloGeneratorTriggers_Fn(%item)"
   ),

NO EMPTY SPACES IN THE STRING!!! The expresion in <> brackets defines the global path to the current item with % sign refering to the index name. The rest of the string calls a trigger function with index as an argument. There can be more indexes in the expresion (thats why the naming is needed).

Link To Scene

You can add a link to any selectable scene object into the trigger explanation message. Here is the general format of the link:

<a href="hscene://currentView?selector=model.path" [select] >Link Text</a>

Where the model.path is any path to selectable model part. The select is an optional argument, and if specified, the object will be selected at the trigger is done. The model path must be defined in CmpMap.fcscdx. The Link Text is any message to the client notification. Example:

addSiloTrigger = { 
   Constraints = [
      [
         #increase number of silos on site
         {
            Variable = "site.inNumberOfSilosUsed",
            Condition   = False, 
            Init := (( maxNumberOfSilosReached )
               ? ( inNumberOfSilosUsed )
               : ( inNumberOfSilosUsed + 1 )), 
            Explanation = (( maxNumberOfSilosReached )
               ? ( "Max number of silos reached - silo not added!" )
               : ( "<a select href='hscene://currentView?selector=gbGeneralSiloSimpleModels.dParts["+inNumberOfSilosUsed.ToString("0")+"]'>New silo</a> was added to the site!" )
            ),
         } 
      ],
   ],
}

VariableScope

A parameter VariableScope can be set for the constraint. With VariableScope = "global", the path to the variable being changed is taken as global, instead of local within InputType.

⚠️ **GitHub.com Fallback** ⚠️