Versions Compared
Key
- This line was added.
- This line was removed.
- Formatting was changed.
Overview
************NOTE: this worked example section of the wiki is now out of date as GELLO is currently at R.2. This code will not work in later versions of the editor. We intend to update this section to R2 GELLO soon. ****************GELLO code will be used to calculate the value of 'Total Cost'. It will retrieve the values from 'Number' and 'Cost' and return the result of one multiplied by the other. Click on the RHS in the pane next to IsCalculated for the 'Total Cost'. Then click on on the far right hand side of this pane, which is now a white background colour.
The first bit of GELLO v.1 code is nearly always this:prefilled and sets the context
No Format let o:observation = parameter[1]Context CEN_Apple_v1::ArchetypeRoot
Now let's set up a local variable to hold the value for instances of the archetype where 'Cost' is entered. Add the following code:
No Format letLet Costcost: Integer = if o.isdefined() then o.find_observation('1.2').value_asPQ().value else 0.0 endiftemplate.Apple.Cost.value.oclAsType(PQ).value
Same again for 'Number' - a bit simpler as it is already a number:
No Format letLet Numbernumber: Integer = if o.isdefined() then o.find_observation('1.3').value_asReal() else 0.0 endif template.Apple.Number.value.oclAsType(Integer)
- Test this code if you like by stepping through it with the Step button Image Removedcompile button.Image Added
Next thing is to do the algorithm line that produces the result:
No Format letLet Resultresult_Real: IntegerReal = Costcost * Numbernumber
But 'Total Cost' is a Physical Quantity*, so the result needs to be returned in this form. This line of code just declares what needs to be returned by the GELLO v. 1 expression:
No Format Factory.PhysicalQuantity (Result, '$')
--- PQ{value = result_Real, unit = '$'}
Info title Note: * It isn't really, but we are using this apple example to learn about such things.
- Running So the whole bit of GELLO code in the MO Gello Editor (which in turn is embedded in the MO Template Editor) looks like:
Image Removed
And the thing running in Preview Archetype:
- Don't forget to save the archetype!!
Table of Contents | ||||
---|---|---|---|---|
|