Application Transaction Context

Smallworld has a way of setting a global context in an application that can be used in every transaction that runs in that application.

Say we want to change the Electricity application in the Cambridge demo. We will add a choice_item that lists the voltages. If we select a voltage, then from then on all cables will be inserted with that voltage.
picker.png

We do this in 3 steps.
1) First create a plugin that provides the choice_item as an action.
2) Embed the action in the application. When the user selects a voltage, set the transaction context. This is the code-snippet:

_pragma(classify_level=basic, topic={demo})
_private _method app_context_plugin.set_app_context(p_voltage)
    ## set the application context. Map the voltage to the value
    ## known in the voltage enumerator for the cable.

    _local _constant map << property_list.new_with(
                    :none, _unset,
                    :lv, "LV",
                    :hv, "11kV",
                    :dv, "132kV")
    _local value << map[p_voltage]
    _self.application.set_transaction_context_element(:voltage,value)
_endmethod
$

3) Next define a pre insert trigger that can pick-up the value and apply it to itself.
This is the code-snippet:
_pragma(classify_level=basic, topic={demo})
_method cable.fire_pre_insert_actions(p_proposed_values)
    ## Pick up the voltage from the transaction context and apply
    ## it to my proposed values.

    _dynamic !current_transaction!
    _local voltage << !current_transaction!.transaction_context[:voltage]
    _if voltage _isnt _unset
    _then
        p_proposed_values[:voltage] << voltage
    _endif
    # return the new set.
    _return p_proposed_values
_endmethod
$

An example plugin is attached to demo the principle.

  • Load the demo module in the Cambridge application (4.3).
  • Embed the action in a toolbar.
  • Define 3 themes (lv, hv and dv). Theme lv should show the cable centerline_lv, joints and supply_points. Theme hv should only show the cable centerline_hv.
  • Start the Professional application and test it. Enjoy!
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License