Skip to content

Commit f07b0d5

Browse files
author
JelteMX
committed
🔥 First release
0 parents  commit f07b0d5

19 files changed

+571
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.DS_Store
2+
dist/tmp

LICENSE

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
The Apache License v2.0
2+
3+
Copyright Jelte Lagendijk <[email protected]> 2020
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.

README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
[![Support](https://img.shields.io/badge/Support-Community%20(no%20active%20support)-orange.svg)](https://docs.mendix.com/developerportal/app-store/app-store-content-support)
2+
[![Studio](https://img.shields.io/badge/Studio%20version-8.0%2B-blue.svg)](https://appstore.home.mendix.com/link/modeler/)
3+
![GitHub release](https://img.shields.io/github/release/JelteMX/mendix-math-module)
4+
![GitHub issues](https://img.shields.io/github/issues/JelteMX/mendix-math-module)
5+
6+
# Math Module for Mendix
7+
8+
![Icon](/assets/AppStoreIcon.png)
9+
10+
Do you feel the need to do more complex calculations in Mendix, but see a lack in capabilities in your Microflows? No worries, the Math Module is here to help you out. This uses the excellent [mXparser libary](https://mathparser.org/) to extend your workflows with more complex calculations.
11+
12+
> **See a demo in action [HERE](https://mathenginetestapp-sandbox.mxapps.io/p/simple)!**
13+
14+
> I am looking for skilled Mendix+Java developers to help me make this even greater. The current set of Java actions are very flexible, but we can make more complex and dedicated actions available in the future. Feel free to contact me on Gitthub or through my [Mendix Developer profile](https://developer.mendixcloud.com/link/profile/overview/24785)
15+
16+
![screenshot](/assets/screenshot-simple.png)
17+
![screenshot](/assets/screenshot-complex.png)
18+
19+
## Java Actions
20+
21+
### Expressions
22+
23+
- **SimpleExpression** - calculate a simple expression that uses a formula you define as a String
24+
- **ComplexExpression** - calculate a more complex expression that uses Arguments
25+
26+
### Function
27+
28+
- **RecursiveFunction** - Do you need to calculate `f(10)` for `f(n)=f(n-2)+f(n-1)`? A recursive function might help you out
29+
30+
### Decimals
31+
32+
- **MoveDecimalPoint** - Move a decimal point in a Decimal
33+
34+
### Conversion
35+
36+
- **ConvertIntToBaseString** - Do you need to represent an Integer (base10) into another form, for example Octal (base8) or Hex (base16)?
37+
38+
## Syntax
39+
40+
The expressions and functions you write can use a whole range of built-in functions and constants. These can be found at [https://github.com/mariuszgromada/MathParser.org-mXparser#built-in-tokens](https://github.com/mariuszgromada/MathParser.org-mXparser#built-in-tokens)
41+
42+
## Libraries used
43+
44+
- mXparser library
45+
- Version 4.3.3
46+
- License: Simplified BSD - Mariusz Gromada
47+
- [link](https://github.com/mariuszgromada/MathParser.org-mXparser/blob/master/LICENSE.txt)
48+
49+
## Adding new Java Actions
50+
51+
You can create new Java Actions using the mXparser library. See [API docs](http://mathparser.org/api/org/mariuszgromada/math/mxparser/package-summary.html).
52+
53+
## License
54+
55+
Apache 2

assets/AppStoreIcon.png

17 KB
Loading

assets/screenshot-complex.png

183 KB
Loading

assets/screenshot-domain.png

66 KB
Loading

assets/screenshot-simple.png

95.5 KB
Loading

dist/MathModule.mpk

404 KB
Binary file not shown.

src/MathModule.mpk

404 KB
Binary file not shown.

src/mathmodule/Misc.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package mathmodule;
2+
3+
import java.math.BigDecimal;
4+
5+
import com.mendix.core.Core;
6+
import com.mendix.systemwideinterfaces.core.IContext;
7+
import com.mendix.systemwideinterfaces.core.IMendixObject;
8+
9+
import mathmodule.proxies.ExpressionResult;
10+
11+
public class Misc {
12+
13+
public static final double MAX_DECIMAL_VALUE = Math.pow(10, 20) - 1;
14+
public static final double MAX_INT_VALUE = Math.pow(2, 31) - 1;
15+
public static final double MAX_LONG_VALUE = Math.pow(2, 63) - 1;
16+
17+
public static IMendixObject getExpressionResult(IContext ctx, double value) {
18+
IMendixObject result = Core.instantiate(ctx, ExpressionResult.getType());
19+
20+
String attrIsValid = ExpressionResult.MemberNames.IsValid.toString();
21+
String attrValue = ExpressionResult.MemberNames.Value.toString();
22+
String attrStringValue = ExpressionResult.MemberNames.StringValue.toString();
23+
String attrHasDecimal = ExpressionResult.MemberNames.HasDecimal.toString();
24+
25+
result.setValue(ctx, attrIsValid, true);
26+
result.setValue(ctx, attrStringValue, String.format("%.16f", value));
27+
28+
if (value > MAX_DECIMAL_VALUE || value < (0 - MAX_DECIMAL_VALUE)) {
29+
result.setValue(ctx, attrHasDecimal, false);
30+
result.setValue(ctx, attrValue, null);
31+
} else {
32+
result.setValue(ctx, attrHasDecimal, true);
33+
result.setValue(ctx, attrValue, new BigDecimal(value));
34+
}
35+
36+
37+
return result;
38+
}
39+
40+
public static IMendixObject getExpressionError(IContext ctx, String error) {
41+
IMendixObject result = Core.instantiate(ctx, ExpressionResult.getType());
42+
43+
String attrIsValid = ExpressionResult.MemberNames.IsValid.toString();
44+
String attrError = ExpressionResult.MemberNames.ErrorMessage.toString();
45+
46+
result.setValue(ctx, attrIsValid, false);
47+
result.setValue(ctx, attrError, error);
48+
49+
return result;
50+
}
51+
}

0 commit comments

Comments
 (0)