Skip to content
AlBal2 edited this page Jun 5, 2019 · 3 revisions

Overview

The Calcs repository contains 7 projects: CalcCore - DLL project - this provides the interfaces and classes that enable the framework. Everything in the Calcs world uses this library. The ICalc interface defines the important functionality that must be present in all 'calculations', and an abstract class, CalcBase, has been provided for convenience and implements the ICalc interface.

CalcMonkey - GHA(DLL) project - makes the framework available in Grasshopper.

Calcs - a WPF client app for consuming calculations. This will load any DLL containing classes that implement ICalc. DynamicRelaxation - DLL project - simple dynamic relaxation solver. Drives the splashscreen animation for the Calcs app.

RunInConsole - console app - used for debugging, will run calcs from the command line.

TestCalcs - DLL project - various classes implementing the ICalc interface.

UnitTestProject1 - unit tests.

Getting Started

The simplest way to get started is to create a new class inheriting the CalcBase class from CalcCore. The SimpleMoment class in TestCalcs is a good example to look at when learning. Key things to be aware of:

  • Any values (both inputs or outputs) that you want to expose to the outside world should be wrapped in one of the CalcValueBase derived classes, currently CalcDouble (for floating point numbers), CalcFilePath (for file paths), CalcFolderPath (for folder paths) and CalcSelectionDoubleList (for string lists, typically used to provide a list of options for input values).

  • CalcBase uses factories for generating input and output values. These are declared as the private fields 'inputs' and 'outputs'. In your constructor, initialise your inputs and outputs using the factories e.g. _myValue = inputs.CreateDoubleCalcValue("test", "sym", "unit", 65); All values created in these factories will be available to the outside world through the GetInputs() and GetOutputs() methods.

  • The UpdateCalc() method is used by clients to update the calculated results, usually following a change to one or more input values. It is recommended to call this from your constructor too.

  • Further descriptive information can be made available through the GetFormulae() method. This returns a list of Formula objects. A Formula object includes the properties Narrative (a string intended to describe a step in the calc), Ref (a string intended to provide a reference), Expression (a list of strings representing the mathematical formulae in LaTeX format), Conclusion (a string intended to provide a conclusion to the calc step), Status (set to one of the CalcStatus enum values - NONE, PASS, FAIL, JUSTPASSED, JUSTFAILED - this information is often used for formatting by clients (e.g. ) and finally Image which contains a bitmap image. You do not need to implement anything here for the calc to work. It is recommended getting your calc working before adding this functionality. If you have anything that takes significant time to generate, it is best to do this in the GetFormulae() method so it is only done when required, not as part of the UpdateCalc() method.

Clone this wiki locally