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+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
// This file was generated by Mendix Studio Pro.
2+
//
3+
// WARNING: Only the following code will be retained when actions are regenerated:
4+
// - the import list
5+
// - the code between BEGIN USER CODE and END USER CODE
6+
// - the code between BEGIN EXTRA CODE and END EXTRA CODE
7+
// Other code you write will be lost the next time you deploy the project.
8+
// Special characters, e.g., é, ö, à, etc. are supported in comments.
9+
10+
package mathmodule.actions;
11+
12+
import com.mendix.systemwideinterfaces.core.IContext;
13+
import com.mendix.webui.CustomJavaAction;
14+
import mathmodule.Misc;
15+
import mathmodule.proxies.ExpressionUseEnum;
16+
import com.mendix.systemwideinterfaces.core.IMendixObject;
17+
import org.mariuszgromada.math.mxparser.Expression;
18+
import java.math.BigDecimal;
19+
import org.mariuszgromada.math.mxparser.Argument;
20+
21+
public class ComplexExpression extends CustomJavaAction<IMendixObject>
22+
{
23+
private java.lang.String Expression;
24+
private java.util.List<IMendixObject> __Arguments;
25+
private java.util.List<mathmodule.proxies.Argument> Arguments;
26+
27+
public ComplexExpression(IContext context, java.lang.String Expression, java.util.List<IMendixObject> Arguments)
28+
{
29+
super(context);
30+
this.Expression = Expression;
31+
this.__Arguments = Arguments;
32+
}
33+
34+
@java.lang.Override
35+
public IMendixObject executeAction() throws Exception
36+
{
37+
this.Arguments = new java.util.ArrayList<mathmodule.proxies.Argument>();
38+
if (__Arguments != null)
39+
for (IMendixObject __ArgumentsElement : __Arguments)
40+
this.Arguments.add(mathmodule.proxies.Argument.initialize(getContext(), __ArgumentsElement));
41+
42+
// BEGIN USER CODE
43+
IContext ctx = this.getContext();
44+
45+
if (this.Expression == "" || this.Expression == null) {
46+
return Misc.getExpressionError(ctx, "Expression cannot be empty");
47+
}
48+
49+
Expression expression = new Expression(this.Expression);
50+
for(mathmodule.proxies.Argument argument : this.Arguments) {
51+
IMendixObject obj = argument.getMendixObject();
52+
53+
String name = obj.getValue(ctx, mathmodule.proxies.Argument.MemberNames.ArgumentName.toString());
54+
BigDecimal value = obj.getValue(ctx, mathmodule.proxies.Argument.MemberNames.Value.toString());
55+
String stringValue = obj.getValue(ctx, mathmodule.proxies.Argument.MemberNames.StringValue.toString());
56+
String enumeration = obj.getValue(ctx, mathmodule.proxies.Argument.MemberNames.Use.toString());
57+
58+
if (enumeration.equals(ExpressionUseEnum.Decimal.name()) && value != null) {
59+
Argument arg = new Argument(name, value.doubleValue());
60+
expression.addArguments(arg);
61+
} else if (enumeration.equals(ExpressionUseEnum.String.name()) && stringValue != null) {
62+
double doubleValue = new Double(stringValue);
63+
if (!Double.isNaN(doubleValue)) {
64+
Argument arg = new Argument(name, doubleValue);
65+
expression.addArguments(arg);
66+
}
67+
}
68+
}
69+
70+
boolean syntaxValid = expression.checkSyntax();
71+
if (syntaxValid) {
72+
73+
double expressionResult = expression.calculate();
74+
boolean afterCalculateSatus = expression.checkSyntax();
75+
76+
if (afterCalculateSatus) {
77+
if (Double.isNaN(expressionResult)) {
78+
return Misc.getExpressionError(ctx, "Expression result is not a number");
79+
}
80+
return Misc.getExpressionResult(ctx, expressionResult);
81+
} else {
82+
return Misc.getExpressionError(ctx, expression.getErrorMessage());
83+
}
84+
85+
} else {
86+
return Misc.getExpressionError(ctx, expression.getErrorMessage());
87+
}
88+
89+
// END USER CODE
90+
}
91+
92+
/**
93+
* Returns a string representation of this action
94+
*/
95+
@java.lang.Override
96+
public java.lang.String toString()
97+
{
98+
return "ComplexExpression";
99+
}
100+
101+
// BEGIN EXTRA CODE
102+
// END EXTRA CODE
103+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// This file was generated by Mendix Studio Pro.
2+
//
3+
// WARNING: Only the following code will be retained when actions are regenerated:
4+
// - the import list
5+
// - the code between BEGIN USER CODE and END USER CODE
6+
// - the code between BEGIN EXTRA CODE and END EXTRA CODE
7+
// Other code you write will be lost the next time you deploy the project.
8+
// Special characters, e.g., é, ö, à, etc. are supported in comments.
9+
10+
package mathmodule.actions;
11+
12+
import com.mendix.systemwideinterfaces.core.IContext;
13+
import com.mendix.webui.CustomJavaAction;
14+
import org.mariuszgromada.math.mxparser.mathcollection.NumberTheory;
15+
16+
public class ConvertIntToBaseString extends CustomJavaAction<java.lang.String>
17+
{
18+
private java.lang.Long Input;
19+
private java.lang.Long Base;
20+
private java.lang.Boolean IncludeBase;
21+
22+
public ConvertIntToBaseString(IContext context, java.lang.Long Input, java.lang.Long Base, java.lang.Boolean IncludeBase)
23+
{
24+
super(context);
25+
this.Input = Input;
26+
this.Base = Base;
27+
this.IncludeBase = IncludeBase;
28+
}
29+
30+
@java.lang.Override
31+
public java.lang.String executeAction() throws Exception
32+
{
33+
// BEGIN USER CODE
34+
int baseInclude = (this.IncludeBase == null ? false : this.IncludeBase) ? 1 : 0;
35+
return NumberTheory.convDecimal2OthBase(this.Input, this.Base.intValue(), baseInclude);
36+
// END USER CODE
37+
}
38+
39+
/**
40+
* Returns a string representation of this action
41+
*/
42+
@java.lang.Override
43+
public java.lang.String toString()
44+
{
45+
return "ConvertIntToBaseString";
46+
}
47+
48+
// BEGIN EXTRA CODE
49+
// END EXTRA CODE
50+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// This file was generated by Mendix Studio Pro.
2+
//
3+
// WARNING: Only the following code will be retained when actions are regenerated:
4+
// - the import list
5+
// - the code between BEGIN USER CODE and END USER CODE
6+
// - the code between BEGIN EXTRA CODE and END EXTRA CODE
7+
// Other code you write will be lost the next time you deploy the project.
8+
// Special characters, e.g., é, ö, à, etc. are supported in comments.
9+
10+
package mathmodule.actions;
11+
12+
import com.mendix.systemwideinterfaces.core.IContext;
13+
import com.mendix.webui.CustomJavaAction;
14+
import mathmodule.proxies.DecimalMoveDirection;
15+
16+
public class DecimalMovePoint extends CustomJavaAction<java.math.BigDecimal>
17+
{
18+
private java.math.BigDecimal Input;
19+
private java.lang.Long MoveAmount;
20+
private mathmodule.proxies.DecimalMoveDirection Direction;
21+
22+
public DecimalMovePoint(IContext context, java.math.BigDecimal Input, java.lang.Long MoveAmount, java.lang.String Direction)
23+
{
24+
super(context);
25+
this.Input = Input;
26+
this.MoveAmount = MoveAmount;
27+
this.Direction = Direction == null ? null : mathmodule.proxies.DecimalMoveDirection.valueOf(Direction);
28+
}
29+
30+
@java.lang.Override
31+
public java.math.BigDecimal executeAction() throws Exception
32+
{
33+
// BEGIN USER CODE
34+
if (this.Input == null) {
35+
return null;
36+
}
37+
if (this.MoveAmount == null) {
38+
return this.Input;
39+
}
40+
int amount = this.MoveAmount.intValue();
41+
if (this.Direction.equals(DecimalMoveDirection.left)) {
42+
return this.Input.movePointLeft(amount);
43+
}
44+
return this.Input.movePointRight(amount);
45+
// END USER CODE
46+
}
47+
48+
/**
49+
* Returns a string representation of this action
50+
*/
51+
@java.lang.Override
52+
public java.lang.String toString()
53+
{
54+
return "DecimalMovePoint";
55+
}
56+
57+
// BEGIN EXTRA CODE
58+
// END EXTRA CODE
59+
}

0 commit comments

Comments
 (0)