/// <summary> /// Updates measurements data /// </summary> void IMeasurements.UpdateMeasurements() { if (IsUpdated) { return; } try { if (par == null) { throw new Exception(DynamicalParameter.UndefinedParameters); } if (measurements == null) { throw new Exception("Formulas are not accepted"); } update(); foreach (int i in feedAliases.Keys) { IMeasurement m = measurements[i]; object r = m.Parameter(); if (r != null) { feedAliases[i].SetValue(r); } } isUpdated = true; } catch (Exception exception) { exception.ShowError(errorLevel); } }
public static bool PerformIterator(this IDataConsumer consumer, IIterator iterator, ITimeMeasureProvider timeProvider, string reason, Func <bool> stop) { try { using (TimeProviderBackup backup = new TimeProviderBackup(consumer, timeProvider, null, reason, 0)) { IDataRuntime runtime = backup.Runtime; IStep st = null; IMeasurement time = timeProvider.TimeMeasurement; if (runtime is IStep) { st = runtime as IStep; st.Step = 0; } iterator.Reset(); double t = (double)time.Parameter(); double last = t; Action <double, double, long> act = runtime.Step(null, (double timer) => { }, reason, null); int i = 0; IEnumerable <object> enu = runtime.AllComponents; while (iterator.Next()) { t = (double)time.Parameter(); act(last, t, i); ++i; if (st != null) { st.Step = i; } last = t; if (stop()) { return(true); } } } return(false); } catch (Exception ex) { ex.ShowError(10); } return(true); }
/// <summary> /// Calculates parameters /// </summary> /// <param name="x">Input</param> /// <param name="selection">Selection</param> /// <param name="y">Output</param> public void Calculate(double[] x, IStructuredSelection selection, double?[] y) { double a = 0; for (int i = 0; i < x.Length; i++) { aliases[i].Value = x[i]; } /*!!!/// TEMP ==================== * * UpdateChildrenData(); * if (DataPerformer.Portable.StaticExtensionDataPerformerPortable.Factory != null) * { * runtime.UpdateAll(); * } * this.FullReset(); * UpdateChildrenData(); * * ///=============*/ // runtime.StartAll(0); runtime.UpdateAll(); int n = 0; for (int i = 0; i < measurementsDitcionary.Count; i++) { IMeasurement m = measurementsDitcionary[i] as IMeasurement; object t = m.Type; if (t.Equals(a)) { y[n] = (double)m.Parameter(); ++n; continue; } else { Array ar = m.Parameter() as Array; for (int j = 0; j < ar.GetLength(0); j++) { y[n] = (double)ar.GetValue(j); ++n; } } } }
/// <summary> /// Updates itself /// </summary> public void Update() { points.Clear(); if ((xm == null) | (ym == null)) { return; } this.FullReset(); IDataConsumer dc = this; dc.UpdateChildrenData(); object ox = xm.Parameter(); object oy = ym.Parameter(); try { double[] x = ox as double[]; if (x == null) { object[] obx = ox as object[]; x = new double[obx.Length]; for (int i = 0; i < x.Length; i++) { x[i] = (double)obx[i]; } } double[] y = oy as double[]; if (y == null) { object[] oby = oy as object[]; y = new double[oby.Length]; for (int i = 0; i < y.Length; i++) { y[i] = (double)oby[i]; } } if (x == null | y == null) { return; } int n = x.Length; if (y.Length < n) { n = y.Length; } for (int i = 0; i < n; i++) { double[] p = new double[] { x[i], y[i] }; points.Add(p); } } catch (Exception ex) { ex.ShowError(10); } }
private void UpdateProxy() { proxy.Update(); foreach (char c in variables.Keys) { object[] o = variables[c] as object[]; IMeasurement m = dictF[c]; o[3] = m.Parameter(); } }
void IMeasurements.UpdateMeasurements() { measurements.UpdateChildrenData(); foreach (IMeasurement m in linkdel.Keys) { linkdel[m](m.Parameter()); } calculation.Time = (double)timeMeasure.Parameter(); calculation.Update(); }
new void Update() { object o = measurement.Parameter(); if (o == bitmap) { return; } bitmap = o as Bitmap; userControlBitmapMeasurement.Bitmap = bitmap; }
IEnumerable <byte[]> Transform(IIterator iterator, Func <bool> stop) { string reason = StaticExtensionEventInterfaces.RealtimeLogAnalysis; using (TimeProviderBackup backup = new TimeProviderBackup(consumer, iterator as ITimeMeasureProvider, null, reason, 0)) { IDataRuntime runtime = backup.Runtime; IStep st = null; IMeasurement time = (iterator as ITimeMeasureProvider).TimeMeasurement; if (runtime is IStep) { st = runtime as IStep; st.Step = 0; } iterator.Reset(); double t = (double)time.Parameter(); double last = t; Action <double, double, long> act = runtime.Step(null, (double timer) => { }, reason, null); int i = 0; while (iterator.Next()) //!!! Unifinished? { t = (double)time.Parameter(); act(last, t, i); ++i; DateTime dt = new DateTime(); dt += TimeSpan.FromSeconds(t); object tuple = new Tuple <DateTime, Dictionary <string, object> >(dt, measurementsWrite.WriteParameters()); yield return(objectToBytes(tuple)); if (stop()) { break; } } } }
void RealtimeUpdate() { if ((bool)conditionMeasure.Parameter()) { int n = output.Length; for (int i = 0; i < n; i++) { output[i] = measures[i].Parameter(); } eventWriter.OnEvent(output); } }
internal void Step() { double x = (double)arg.Parameter(); if (size > 0) { if (l.Count >= size) { l.RemoveAt(0); } } l.Add(new object[] { x, val.Parameter() }); }
void RealtimeUpdate() { if (!test()) { return; } bool soundCondition = (bool)condition.Parameter(); // Sound condition if (soundCondition) { string currentSound = sound.Parameter() as string; // Sound file Play(currentSound); } // Plays sound }
/// <summary> /// Updates measurements data /// </summary> public override void UpdateMeasurements() { double t = (double)time.Parameter(); if (t == to) { return; } foreach (FunctionDyn f in fd) { f.Step(); } global[2] = 0; to = t; }
/// <summary> /// Gets one dimensional array by name /// </summary> /// <param name="ao">Associated object</param> /// <param name="name">Full name of array</param> /// <returns>The array</returns> public static Array GetOneDimensionRealArray(this IAssociatedObject ao, string name) { INamedComponent nc = null; if (ao is INamedComponent) { nc = ao as INamedComponent; } else { nc = ao.Object as INamedComponent; } IDesktop desktop = nc.Root.Desktop; Array arr = null; desktop.ForEach <IMeasurements>((IMeasurements m) => { IAssociatedObject aob = m as IAssociatedObject; INamedComponent ncm = aob.Object as INamedComponent; string nm = ncm.GetName(desktop); for (int i = 0; i < m.Count; i++) { try { IMeasurement mea = m[i]; if (mea == null) { continue; } string nn = nm + "." + mea.Name; if (name.Equals(nn)) { if (arr != null) { ao.Throw("Ambigous"); } arr = mea.Parameter() as Array; break; } } catch (Exception ex) { ex.ShowError(10); } } }); return(arr); }
/// <summary> /// Trasformation /// </summary> /// <param name="input">Input</param> /// <param name="output">Output</param> public void Transform(object[] input, object[] output) { for (int i = 0; i < input.Length; i++) { object[] al = aliases[i]; IAlias a = al[0] as IAlias; string s = al[1] as string; a[s] = input[i]; } consumer.ResetAll(); consumer.UpdateChildrenData(); for (int i = 0; i < output.Length; i++) { IMeasurement m = measures[i]; output[i] = m.Parameter(); } }
void IMeasurements.UpdateMeasurements() { if (isUpdated) { return; } if (condition != null) { if (!(bool)condition.Parameter()) { isUpdated = true; return; } } Update(); isUpdated = true; }
/// <summary> /// Updates itself /// </summary> protected void Update() { try { if (isUpdated) { return; } cons.UpdateChildrenData(); Array input = measure.Parameter() as Array; int n = input.Length; Array.Copy(input, val, n); } catch (Exception e) { e.ShowError(10); this.Throw(e); } }
/// <summary> /// Updates measurements data /// </summary> public void UpdateMeasurements() { if (IsUpdated) { return; } try { UpdateChildrenData(); result[0, 0] = 0; result[1, 0] = 0; double x = (double)input.Parameter(); IDerivation der = input as IDerivation; double d = Measurement.GetDouble(der.Derivation); for (int i = 0; i < series[0].Count; i++) { double om = series[0][i, 0]; d *= om; double a = x * om; double s = Math.Sin(a); double c = Math.Cos(a); double re = series[0][i, 1] * c + series[1][i, 1] * s; double im = -series[0][i, 1] * s + series[1][i, 1] * c; result[0, 0] += re; result[1, 0] += im; result[0, 1] += d * im; result[1, 1] -= d * re; } isUpdated = true; } catch (Exception e) { e.ShowError(10); this.Throw(e); } }
/*public override double[,] RelativeMatrix * { * get * { * return base.RelativeMatrix; * } * set * { * base.RelativeMatrix = value; * / for (int i = 0; i < 4; i++) * { * initialConditions[i + 6] = relativeQuaternion[i]; * } * } * }*/ #endregion #region IDifferentialEquationSolver Members void IDifferentialEquationSolver.CalculateDerivations() { //IReferenceFrame f = this; //ReferenceFrame frame = f.Own; SetAliases(); IDataConsumer cons = this; int i = 0; cons.Reset(); cons.UpdateChildrenData(); //Filling of massive of forces and moments using results of calculations of formula trees for (i = 0; i < 12; i++) { forces[i] = (double)measures[i].Parameter(); } //Filling the part, responding to derivation of radius-vector /*for (i = 0; i < 3; i++) * { * result[i, 1] = result[3 + i, 0]; * }*/ int k = 0; for (i = 0; i < 3; i++) { for (int j = i; j < 3; j++) { IMeasurement min = inertia[k]; ++k; if (min != null) { double jin = (double)min.Parameter(); J[i, j] = jin; J[j, i] = jin; } } } IMeasurement mm = inertia[6]; if (mm != null) { unMass = (double)mm.Parameter(); unMass = 1 / unMass; } //Filling the part, responding to derivation of linear velocity for (i = 0; i < 3; i++) { linAccAbsolute[i] = forces[6 + i] * unMass; } double[,] T = Relative.Matrix; RealMatrix.Multiply(linAccAbsolute, T, aux); for (i = 0; i < 3; i++) { linAccAbsolute[i] = forces[i] * unMass + aux[i]; } RealMatrix.Multiply(J, omega, aux); StaticExtensionVector3D.VectorPoduct(omega, aux, aux1); RealMatrix.Add(aux1, 0, forces, 9, aux, 0, 3); Array.Copy(forces, 3, aux1, 0, 3); RealMatrix.Multiply(aux1, T, aux2); RealMatrix.Add(aux2, 0, forces, 9, aux1, 0, 3); RealMatrix.Add(aux1, 0, aux, 0, aux2, 0, 3); RealMatrix.Multiply(L, aux2, epsRelative); aux4d[0] = 0; Array.Copy(omega, 0, aux4d, 1, 3); StaticExtensionVector3D.QuaternionInvertMultiply(relativeQuaternion, aux4d, quaternionDervation); for (i = 0; i < 3; i++) { quaternionDervation[i] *= 0.5; } SetRelative(); Update(); }
/// <summary> /// Creates document with arrays /// </summary> /// <param name="consumer">Data consumer</param> /// <returns>Xml document</returns> public static XmlDocument GetArraysXmlDocument(IDataConsumer consumer) { ArrayList meas = new ArrayList(); int[] r = null; int n = consumer.Count; for (int i = 0; i < n; i++) { IMeasurements mea = consumer[i]; int k = mea.Count; for (int j = 0; j < k; j++) { IMeasurement m = mea[j]; object type = m.Type; if (!(type is ArrayReturnType)) { continue; } ArrayReturnType art = type as ArrayReturnType; int[] rr = art.Dimension; if (rr.Length > 1) { continue; } if (r == null) { r = rr; } if (r[0] != rr[0]) { continue; } meas.Add(m); } } if (r == null) { return(null); } XmlDocument doc = new XmlDocument(); doc.LoadXml("<?xml version=\"1.0\"?><ExperimentalData><Root></Root></ExperimentalData>"); XmlElement root = doc.GetElementsByTagName("Root")[0] as XmlElement; XmlAttribute att = doc.CreateAttribute("uid"); att.Value = Guid.NewGuid() + ""; root.Attributes.Append(att); att = doc.CreateAttribute("time"); att.Value = DateTime.Now + ""; root.Attributes.Append(att); XmlElement descr = doc.CreateElement("ParametersDescription"); root.AppendChild(descr); for (int i = 0; i < meas.Count; i++) { IMeasurement m = meas[i] as IMeasurement; XmlElement e = doc.CreateElement("ParameterDescription"); descr.AppendChild(e); att = doc.CreateAttribute("id"); att.Value = i + ""; e.Attributes.Append(att); att = doc.CreateAttribute("name"); att.Value = m.Name; e.Attributes.Append(att); } XmlElement results = doc.CreateElement("Results"); root.AppendChild(results); for (int i = 0; i < r[0]; i++) { XmlElement result = doc.CreateElement("Result"); results.AppendChild(result); for (int j = 0; j < meas.Count; j++) { IMeasurement mea = meas[j] as IMeasurement; XmlElement par = doc.CreateElement("Parameter"); result.AppendChild(par); att = doc.CreateAttribute("id"); att.Value = j + ""; par.Attributes.Append(att); att = doc.CreateAttribute("value"); object[] o = mea.Parameter() as object[]; att.Value = o[i] + ""; par.Attributes.Append(att); } } return(doc); }
internal object GetValue() { return(measure.Parameter()); }
/// <summary> /// Process /// </summary> private void Process() { IDataConsumer cons = this; if (provider == null) { bmp = null; return; } if (provider.Bitmap == null) { return; } if (colorAliases == null) { return; } if (extColors == null) { return; } Bitmap b = provider.Bitmap; if (b == null) { return; } bmp = new Bitmap(b.Width, b.Height); int right = colorAliases.GetLength(0) - left; int bottom = colorAliases.GetLength(1) - top; for (int i = 0; i < bmp.Width; i++) { int ii = i - left; if ((ii < 0) | (i + right >= bmp.Width)) { continue; } for (int j = 0; j < bmp.Height; j++) { int jj = j - top; if ((jj < 0) | (j + bottom >= bmp.Height)) { continue; } double x = (double)i; double y = (double)j; if (coord[0] != null) { coord[0].SetValue(x); } if (coord[1] != null) { coord[1].SetValue(y); } for (int k = 0; k < extColors.GetLength(0); k++) { int xc = ii + k; for (int l = 0; l < extColors.GetLength(1); l++) { int yc = jj + l; Color c = b.GetPixel(xc, yc); hc[0] = c.R; hc[1] = c.G; hc[2] = c.B; for (int m = 0; m < hc.Length; m++) { AliasName ext = extColors[k, l, m]; if (ext != null) { ext.SetValue(((double)hc[m]) / 255); } } } } update(); for (int n = 0; n < measures.Length; n++) { IMeasurement mea = measures[n]; if (mea == null) { hco[n] = 0; } else { double cd = (double)mea.Parameter(); int cn = (int)(cd * 255); if (cn > 255) { cn = 255; } hco[n] = cn; } } Color co = Color.FromArgb(255, hco[0], hco[1], hco[2]); bmp.SetPixel(i, j, co); } } }
/// <summary> /// Creates Xml document /// </summary> /// <param name="consumer">Data consumer</param> /// <param name="collection">Components</param> /// <param name="input">Input</param> /// <param name="start">Start</param> /// <param name="step">Step</param> /// <param name="count">Count</param> /// <returns>Result</returns> static public XmlDocument CreateXmlDocument(this IDataConsumer consumer, XmlDocument input, double start, double step, int count) { List <string> p = new List <string>(); IMeasurement cond = null; string arg = null; Dictionary <string, Func <Func <object> > > d = new Dictionary <string, Func <Func <object> > >(); XmlElement r = input.DocumentElement; foreach (XmlElement e in r.ChildNodes) { string name = e.Name; if (name.Equals("Condition")) { cond = consumer.FindMeasurement(e.InnerText, true); continue; } if (name.Equals("Argument")) { arg = e.InnerText; continue; } if (name.Equals("Parameters")) { XmlNodeList nl = e.ChildNodes; foreach (XmlElement xp in nl) { string pn = null; string pv = null; foreach (XmlElement xpp in xp.ChildNodes) { string npp = xpp.Name; if (npp.Equals("Name")) { pn = xpp.InnerText; continue; } pv = xpp.InnerText; } IMeasurement mcc = consumer.FindMeasurement(pn, false); d[pv] = mcc.ToValueHolder(); } } } XmlParameterWriter xpv = new XmlParameterWriter(null); IParameterWriter pvv = xpv; Action acts = () => { Dictionary <string, string> dpp = new Dictionary <string, string>(); foreach (string k in d.Keys) { object v = d[k]()(); FormulaMeasurement.CheckValue(v); dpp[k] = v + ""; } pvv.Write(dpp); }; Action act = (cond == null) ? acts : () => { foreach (string k in d.Keys) { object v = d[k]()(); FormulaMeasurement.CheckValue(v); } if ((bool)cond.Parameter()) { acts(); } }; try { consumer.PerformFixed(start, step, count, StaticExtensionDataPerformerInterfaces.Calculation, 0, act); } catch (Exception e) { e.ShowError(10); } return(xpv.Document); }
/// <summary> /// Updates itself /// </summary> public void Update() { o[0] = disassembly.Disassembly(measure.Parameter()); }
static object GetParameter(IMeasurement measurement) { return(measurement.Parameter()); }
object IObjectOperation.this[object[] x] { get { return(measurement.Parameter()); } }
/// <summary> /// Updates itself /// </summary> public override void Update() { try { this.FullReset(); IDataConsumer cons = this; cons.UpdateChildrenData(); ReferenceFrame relative = Relative; IPosition p = relative; double[] x = p.Position; ReferenceFrame parent = this.GetParentFrame(); for (int i = 0; i < 3; i++) { x[i] = (double)measurements[i].Parameter(); } if (relative is IVelocity) { IVelocity vel = relative as IVelocity; double[] v = vel.Velocity; for (int i = 0; i < 3; i++) { IDerivation d = measurements[i] as IDerivation; v[i] = Measurement.GetDouble(d.Derivation); } } double[] qua = relative.Quaternion; for (int i = 0; i < qua.Length; i++) { IMeasurement m = measurements[i + 3]; qua[i] = (double)m.Parameter(); } relative.SetMatrix(); if (relative is IAngularVelocity) { IAngularVelocity av = relative as IAngularVelocity; double[] om = av.Omega; IOrientation or = relative as IOrientation; for (int i = 0; i < 4; i++) { IDerivation d = measurements[i + 3] as IDerivation; der[i] = Measurement.GetDouble(d.Derivation); } Vector3D.StaticExtensionVector3D.CalculateDynamics(or.Quaternion, der, om, qd); } if (relative is IAcceleration) { IAcceleration acc = relative as IAcceleration; IAngularAcceleration anc = relative as IAngularAcceleration; double[] linacc = acc.RelativeAcceleration; for (int i = 0; i < linacc.Length; i++) { linacc[i] = Measurement.GetDouble(secondDeriM[i]); } for (int i = 0; i < 4; i++) { angsec[i] = Measurement.GetDouble(secondDeriM[i + 3]); } IAngularVelocity av = relative as IAngularVelocity; double[] om = av.Omega; IOrientation or = relative as IOrientation; double[] angacc = anc.AngularAcceleration; Vector3D.StaticExtensionVector3D.CalculateAcceleratedDynamics(or.Quaternion, der, om, qd, angsec, angacc); } base.Update(); } catch (Exception exception) { exception.ShowError(10); //!!! OLD this.Throw(ex); } }