Plugin API Dokumentation
Plugin API Dokumentation
Eine Dokumentation der Schnittstellen zur Programmierung von Plugins und Skripten. Diese Dokumentation werde ich in englischer Sprache übernehmen. Damit sollen falsche Übersetzungen und Verständnissfehler ausgeschlossen werden.
- ThisApplication.AddLogMessage
([int level,] string format [, object zero, object one, ...])
Adds a message to the diagnostic display. Optional level is the logging level, format is the messages, and markers of the form {0}, {1}, etc will be replaced by the string value of the object.
- ThisApplication.ClearLogMessages()
Clears the diagnostic messages.
- Vector2F()
Creates an undefined vector (the x & y are NaN's)
- Vector2F(double x, double y)
Creates a defined vector
- Vector2F(Point2F a, Point2F b)
Creates a vector from a to b.
- static double Determinant(Vector2F a, Vector2F b)
Returns the magnitude of the cross product of a and b, i.e. a.X*b.Y - a.Y*b.X. This is a handy way to figure out what side of a line a point is one. Given a line AB and a point P, P is to the right of AB if Vector2F.Determinant(new Vector2F(A, P), new Vector2F (A, B)) is greater than zero. With unit vectors it gives you the sine of the angle between them.
- static double DotProduct(Vector2F a, Vector2F b)
Returns the dot product of a and b, i.e. a.X*b.X + a.Y*b.Y. With a unit vector it gives you the component of the other vector along the direction of the unit vector. With two unit vectors it gives you the cosine of the angle between them.
- Vector2F Unit()
Unit vector in the corresponding direction.
- Vector2F Normal()
Normal vector to the right side of the vector, e.g. (y, -x)
- void Invert()
Flips the vector in place.
- double Length
Length of the vector.
- Vector3F()
Creates an undefined vector
- Vector3F(double x, double y, double z)
Creates a defined vector
- Vector3F(Point3F a, Point3F b)
Creates a vector from a to b.
- static Vector3F CrossProduct(Vector3F a, Vector3F b)
Returns the cross product of a and b. With unit vectors it gives you the sine of the angle between them.
- static double DotProduct(Vector3F a, Vector3F b)
Returns the dot product of a and b, i.e. a.X*b.X + a.Y*b.Y. With a unit vector it gives you the component of the other vector along the direction of the unit vector. With two unit vectors it gives you the cosine of the angle between them.
- Vector3F Unit()
Unit vector in the corresponding direction.
- double Length
Length of the vector.
This one is a bit hard and I don't completely understand how it's intended to be used. However, you need it for properties displayed in the property sheet on the UI for MOPs, etc.
There's a status enum State, with values Default, Auto, and Value (as well as some error statuses). There's a boolean flag IsCacheSet indicating that a cached value is available. There's also two value properties, Value and Cached. Cached seems to be set when auto values are computed. Value gets set when a user-specified value is entered.
new CBValue<T>(someTval) gives you a CBValue with both Cached and Value set to someTval, the State set to Value, and IsCacheSet true.
Likewise, .setValue(val) sets both Cached and Value to val, the State set to Value, and IsCacheSet true.
.setCached(val) sets Cached to val and IsCacheSet to true. It leaves Value and State alone.
Setting Value and Cached directly have no other side effects.
Setting the State to Default doesn't do anything else. In particular, if you define a DefaultValue attribute for a CBValue property, it's ignored.
There's also an interface named ICBValueHost that defines some entry points for refreshing values. MachineOp will call EvaluateAutoCBValue(ICBValue toset, string name) after each property change on a MachineOp once for every property currently set to auto. This allows the automatic values to be recomputed whenever something changes.
As far as I can tell, you need a public CBValue property and a private backing CBValue field for each parameter on a machine op.
For example:
public CBValue<double> ToolVAngle {
set {
if (value.IsValue && (value.Value <= 0 || 180 <= value.Value)) {
_toolVAngle.SetState(CBValueStates.Error);
ThisApplication.AddLogMessage(
ERROR, "ToolVAngle must be between 0 and 180 degrees.");
return;
}
_toolVAngle = value;
if (_toolVAngle.IsDefault) {
_toolVAngle.SetCache(DEFAULT_TOOL_V_ANGLE);
_toolVAngle.Value = _toolVAngle.Cached; // necessary/desirable ??
}
}
get { return _toolVAngle; }
}
private CBValue<double> _toolVAngle;
seems to work properly.