forked from ZeraGmbH/Blockly.Net
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Started to add some documentation (ZeraGmbH#19)
* Introduced model cache helper. * Use automatic model dependency resolving to simplify customization. * Review and cleanups. * Added EnumBlock.md. * ModelBlock.md added. * Added BlocklyExtensions.md.
- Loading branch information
Showing
6 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Customization | ||
|
||
[tbd] | ||
|
||
In addition to adding custom block implementations the customization infrastructure can create [enumeration](EnumBlock.md) or [data model](ModelBlock.md) blocks directly from C# types. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Enumeration blocks | ||
|
||
Using _AddEnum<T>(blocklyType, displayName)_ a blockly definition is created which describes the enumeration indicated by the model type parameter _T_ which is contraint to be some _Enum_. | ||
|
||
The corresponding implementation type will be _EnumBlock<T>_ where the evaluation will just use the string field _VALUE_ and convert it to the target type using _Enum.Parse(typeof(T), ...)_. The field will be provided as a blockly _field_dropdown_. | ||
|
||
```csharp | ||
[JsonConverter(typeof(JsonStringEnumConverter))] | ||
public enum ErrorComparisionResult | ||
{ | ||
NotAvailable = 0, | ||
InRange = 1, | ||
TooLow = 2, | ||
TooHigh = 3, | ||
} | ||
``` | ||
|
||
```csharp | ||
builder.AddEnum<ErrorComparisionResult>("error_measurement_comparison", "Error Measurement Comparision"); | ||
``` | ||
|
||
![Enumeration block](EnumBlock.png) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Model blocks | ||
|
||
A blocky definition for a model block is created using _AddModel<T>(blocklyType, displayName)_. The type parameter _T_ is constraint to be a _class_ and having a parameterless constructor. The block implementation is based on _ModelBlock<T>_ and the evaluation method will start with using the parameterless constructor to create a new empty instance of a model. Then all supported properties of the model will be calculated using the corresponding blockly value and stored in the new instance - including some basic conversions to adjust to the required C# type if possible. This instance is then the result of the evaluation of the model block. | ||
|
||
For each supported property the blocky definition will get a corresponding value. A property is supported if the data type conforms to one of the following rules: | ||
|
||
1. some enumeration | ||
2. _bool_, _bool?_, _double_, _double?_, _long_, _long?_, _int_, _int?_ or _string_ | ||
3. another model block | ||
4. _Dictionary<TKey, TValue>_ - the _TKey_ key type must be an enumeration and _TValue_ a supported type | ||
5. _List<T>_ where _T_ is a supported type - but not a _List_ itself | ||
|
||
Properties attributed with the _System.Text.Json.Serialization.JsonIgnoreAttribute_ or which are read only or write only are not included in the block definition. | ||
|
||
The block definition will include a _check_ on each property made available as a value. For _List_ _check_ will contain two checks: one the untyped blockly _Array_ and a special type _Array(type)_ where _type_ is the blockly type name of each array element. This can be used in the frontend to provide a more sophisticated choice of allowed values for a property. | ||
|
||
If the property type is supported by one of the two first rules a corresponding shadow block is added to the toolbox entry. | ||
|
||
```csharp | ||
public class DutRegisterInfo | ||
{ | ||
public DutRegisterTypes Type { get; set; } | ||
public string Address { get; set; } = null!; | ||
public DutRegisterUnits Unit { get; set; } | ||
public double Scale { get; set; } | ||
} | ||
``` | ||
|
||
```csharp | ||
builder.AddModel<DutRegisterInfo>("dut_register_info", "Register Information for a Device under Test"); | ||
``` | ||
|
||
![Model block](ModelBlock.png) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.