public virtual FloatElement CreateFloatElement(XString name, float value) { System.IntPtr cPtr = SharingClientPINVOKE.ObjectElement_CreateFloatElement(swigCPtr, XString.getCPtr(name), value); FloatElement ret = (cPtr == System.IntPtr.Zero) ? null : new FloatElement(cPtr, true); return(ret); }
public static FloatElement Cast(Element element) { global::System.IntPtr cPtr = SharingClientPINVOKE.FloatElement_Cast(Element.getCPtr(element)); FloatElement ret = (cPtr == global::System.IntPtr.Zero) ? null : new FloatElement(cPtr, true); return(ret); }
private float GenerateFloat(FloatElement floatElement) { var randDouble = GenerateDouble(new DoubleElement { Type = "Double", MinValue = (double)floatElement.MinValue, MaxValue = (double)floatElement.MaxValue, ExcludeZero = floatElement.ExcludeZero }); return((float)randDouble); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); var bindings = this.CreateInlineBindingTarget<SecondViewModel>(); var floater = new FloatElement("Float?").Bind(bindings, vm => vm.Temperature); floater.MinValue = 32; floater.MaxValue = 212; Root = new RootElement("Example Root") { new Section("Date") { new DateElement("Date").Bind(bindings, vm => vm.When), new StringElement("Date is").Bind(bindings, vm => vm.When), }, new Section("Time") { new TimeElement("Time").Bind(bindings, vm => vm.Duration), new StringElement("Time is").Bind(bindings, vm => vm.Duration), }, new Section("Float") { floater, new StringElement("Float is").Bind(bindings, vm => vm.Temperature), }, new Section("Todo:") { new StringElement("RadioElement & Group"), new StringElement("Multiline"), new StringElement("Html"), new StringElement("Image"), new StringElement("View"), new StringElement("Html"), new StringElement("WebContent"), new StringElement("Achievement"), new StringElement("General 'Options' on lots of cell types"), new StringElement("General Resource ID overrides"), }, }; }
public long WriteElement(FileStream writer) { MasterElement segmentInfoElement = MatroskaDocTypes.Info.GetInstance(); StringElement writingAppElement = MatroskaDocTypes.WritingApp.GetInstance(); writingAppElement.Value = "Matroska File Writer v1.0 C#"; StringElement muxingAppElement = MatroskaDocTypes.MuxingApp.GetInstance(); muxingAppElement.Value = ".NET EBML v1.0"; DateElement dateElement = MatroskaDocTypes.DateUTC.GetInstance(); dateElement.Date = SegmentDate; UnsignedIntegerElement timecodeScaleElement = MatroskaDocTypes.TimecodeScale.GetInstance(); timecodeScaleElement.Value = TimecodeScale; segmentInfoElement.AddChildElement(dateElement); segmentInfoElement.AddChildElement(timecodeScaleElement); if (Duration != null) { FloatElement durationElement = MatroskaDocTypes.Duration.GetInstance(); durationElement.Value = (double)Duration; segmentInfoElement.AddChildElement(durationElement); } segmentInfoElement.AddChildElement(writingAppElement); segmentInfoElement.AddChildElement(muxingAppElement); ulong len = segmentInfoElement.WriteElement(writer); VoidElement spacer = new VoidElement((ulong)BLOCK_SIZE - len); spacer.WriteElement(writer); return(1); }
void SubMenuItem_1_Click(object sender, EventArgs e) { Object value = null; ToolStripMenuItem MenuItem = sender as ToolStripMenuItem; if (MenuItem != null) { switch (MenuItem.Text) { case "图表": FloatElement Element = new FloatElement(); ActiveSheet.AddShape(Element); Element.setName(string.Format("图表_{0}", ActiveSheet.DrawingContainer.ContainedObjects.Count)); value = new ChartPainter(); Element.setValue(value); Rectangle RowHeaderRectangle = FpSpread.GetRowHeaderRectangle(0); Rectangle ColumnHeaderRectangle = FpSpread.GetColumnHeaderRectangle(0); Point point = new Point(Element.Left + RowHeaderRectangle.Width, Element.Top + ColumnHeaderRectangle.Height); CellRange range = FpSpread.GetCellFromPixel(0, 0, point.X, point.Y); Rectangle r = FpSpread.GetCellRectangle(0, 0, range.Row, range.Column); Element.setRow(range.Row); Element.setColumn(range.Column); Element.setLeftDistance(point.X - r.Left); Element.setTopDistance(point.Y - r.Top); break; } if (value == null) { String msg = "当前版本不支持" + MenuItem.Text + "报表浮动元素。"; MessageBox.Show(msg, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
public override void AddFromRemote(Element remoteElement) { NetworkElement = remoteElement; element = FloatElement.Cast(remoteElement); value = element.GetValue(); }
public static RootElement TestElements() { RootElement re1 = new RootElement("re1"); Debug.WriteLine(re1.ToString()); Section s1 = new Section(); Debug.WriteLine(s1.ToString()); //Section s2 = new Section(new Android.Views.View(a1)); //Debug.WriteLine(s2.ToString()); Section s3 = new Section("s3"); Debug.WriteLine(s3.ToString()); //Section s4 = new Section // ( // new Android.Views.View(a1) // , new Android.Views.View(a1) // ); //Debug.WriteLine(s4.ToString()); Section s5 = new Section("caption", "footer"); Debug.WriteLine(s5.ToString()); StringElement se1 = new StringElement("se1"); Debug.WriteLine(se1.ToString()); StringElement se2 = new StringElement("se2", delegate() { }); Debug.WriteLine(se2.ToString()); //StringElement se3 = new StringElement("se3", 4); StringElement se4 = new StringElement("se4", "v4"); Debug.WriteLine(se4.ToString()); //StringElement se5 = new StringElement("se5", "v5", delegate() { }); // removed - protected (all with LayoutID) // StringElement se6 = new StringElement("se6", "v6", 4); // Debug.WriteLine(se6.ToString()); // not cross platform! // TODO: make it!?!?!? // AchievementElement BooleanElement be1 = new BooleanElement("be1", true); Debug.WriteLine(be1.ToString()); BooleanElement be2 = new BooleanElement("be2", false, "key"); Debug.WriteLine(be2.ToString()); // Abstract // BoolElement be3 = new BoolElement("be3", true); CheckboxElement cb1 = new CheckboxElement("cb1"); Debug.WriteLine(cb1.ToString()); CheckboxElement cb2 = new CheckboxElement("cb2", true); Debug.WriteLine(cb2.ToString()); CheckboxElement cb3 = new CheckboxElement("cb3", false, "group1"); Debug.WriteLine(cb3.ToString()); CheckboxElement cb4 = new CheckboxElement("cb4", false, "subcaption", "group2"); Debug.WriteLine(cb4.ToString()); DateElement de1 = new DateElement("dt1", DateTime.Now); Debug.WriteLine(de1.ToString()); // TODO: see issues // https://github.com/kevinmcmahon/MonoDroid.Dialog/issues?page=1&state=open EntryElement ee1 = new EntryElement("ee1", "ee1"); Debug.WriteLine(ee1.ToString()); EntryElement ee2 = new EntryElement("ee2", "ee2 placeholder", "ee2 value"); Debug.WriteLine(ee2.ToString()); EntryElement ee3 = new EntryElement("ee3", "ee3 placeholder", "ee3 value", true); Debug.WriteLine(ee3.ToString()); FloatElement fe1 = new FloatElement("fe1"); Debug.WriteLine(fe1.ToString()); FloatElement fe2 = new FloatElement(-0.1f, 0.1f, 3.2f); Debug.WriteLine(fe2.ToString()); FloatElement fe3 = new FloatElement ( null , null // no ctors new Android.Graphics.Bitmap() , 1.0f ); Debug.WriteLine(fe3.ToString()); HtmlElement he1 = new HtmlElement("he1", "http://holisiticware.net"); Debug.WriteLine(he1.ToString()); // TODO: image as filename - cross-platform ImageElement ie1 = new ImageElement(null); Debug.WriteLine(ie1.ToString()); // TODO: not in Kevin's MA.D // ImageStringElement MultilineElement me1 = new MultilineElement("me1"); Debug.WriteLine(me1.ToString()); MultilineElement me2 = new MultilineElement("me2", delegate() { }); Debug.WriteLine(me2.ToString()); MultilineElement me3 = new MultilineElement("me3", "me3 value"); Debug.WriteLine(me3.ToString()); RadioElement rde1 = new RadioElement("rde1"); Debug.WriteLine(rde1.ToString()); RadioElement rde2 = new RadioElement("rde1", "group3"); Debug.WriteLine(rde2.ToString()); // TODO: not in Kevin's MA.D // StyledMultilineElement TimeElement te1 = new TimeElement("TimeElement", DateTime.Now); Debug.WriteLine(te1.ToString()); re1.Add(s1); //re1.Add(s2); re1.Add(s3); //re1.Add(s4); re1.Add(s5); return(re1); }
private void Populate(object callbacks, object o, RootElement root) { MemberInfo last_radio_index = null; var members = o.GetType().GetMembers(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); Section section = null; foreach (var mi in members) { Type mType = GetTypeForMember(mi); if (mType == null) { continue; } string caption = null; object[] attrs = mi.GetCustomAttributes(false); bool skip = false; foreach (var attr in attrs) { if (attr is SkipAttribute || attr is System.Runtime.CompilerServices.CompilerGeneratedAttribute) { skip = true; } else if (attr is CaptionAttribute) { caption = ((CaptionAttribute)attr).Caption; } else if (attr is SectionAttribute) { if (section != null) { root.Add(section); } var sa = attr as SectionAttribute; section = new Section(sa.Caption, sa.Footer); } } if (skip) { continue; } if (caption == null) { caption = MakeCaption(mi.Name); } if (section == null) { section = new Section(); } Element element = null; if (mType == typeof(string)) { PasswordAttribute pa = null; AlignmentAttribute align = null; EntryAttribute ea = null; object html = null; Action invoke = null; bool multi = false; foreach (object attr in attrs) { if (attr is PasswordAttribute) { pa = attr as PasswordAttribute; } else if (attr is EntryAttribute) { ea = attr as EntryAttribute; } else if (attr is MultilineAttribute) { multi = true; } else if (attr is HtmlAttribute) { html = attr; } else if (attr is AlignmentAttribute) { align = attr as AlignmentAttribute; } if (attr is OnTapAttribute) { string mname = ((OnTapAttribute)attr).Method; if (callbacks == null) { throw new Exception( "Your class contains [OnTap] attributes, but you passed a null object for `context' in the constructor"); } var method = callbacks.GetType().GetMethod(mname); if (method == null) { throw new Exception("Did not find method " + mname); } invoke = delegate { method.Invoke(method.IsStatic ? null : callbacks, new object[0]); }; } } var value = (string)GetValue(mi, o); if (pa != null) { element = new EntryElement(caption, pa.Placeholder, value, true); } else if (ea != null) { element = new EntryElement(caption, ea.Placeholder, value) { KeyboardType = ea.KeyboardType } } ; else if (multi) { element = new MultilineElement(caption, value); } else if (html != null) { element = new HtmlElement(caption, value); } else { var selement = new StringElement(caption, value); element = selement; if (align != null) { selement.Alignment = align.Alignment; } } if (invoke != null) { (element).Tapped += invoke; } } else if (mType == typeof(float)) { var floatElement = new FloatElement(null, null, (float)GetValue(mi, o)); floatElement.Caption = caption; element = floatElement; foreach (object attr in attrs) { if (attr is RangeAttribute) { var ra = attr as RangeAttribute; floatElement.MinValue = ra.Low; floatElement.MaxValue = ra.High; floatElement.ShowCaption = ra.ShowCaption; } } } else if (mType == typeof(bool)) { bool checkbox = false; foreach (object attr in attrs) { if (attr is CheckboxAttribute) { checkbox = true; } } if (checkbox) { element = new CheckboxElement(caption, (bool)GetValue(mi, o)); } else { element = new BooleanElement(caption, (bool)GetValue(mi, o)); } } else if (mType == typeof(DateTime)) { var dateTime = (DateTime)GetValue(mi, o); bool asDate = false, asTime = false; foreach (object attr in attrs) { if (attr is DateAttribute) { asDate = true; } else if (attr is TimeAttribute) { asTime = true; } } if (asDate) { element = new DateElement(caption, dateTime); } else if (asTime) { element = new TimeElement(caption, dateTime); } else { element = new DateTimeElement(caption, dateTime); } } else if (mType.IsEnum) { var csection = new Section(); ulong evalue = Convert.ToUInt64(GetValue(mi, o), null); int idx = 0; int selected = 0; foreach (var fi in mType.GetFields(BindingFlags.Public | BindingFlags.Static)) { ulong v = Convert.ToUInt64(GetValue(fi, null)); if (v == evalue) { selected = idx; } var ca = Attribute.GetCustomAttribute(fi, typeof(CaptionAttribute)) as CaptionAttribute; csection.Add(new RadioElement(ca != null ? ca.Caption : MakeCaption(fi.Name))); idx++; } element = new RootElement(caption, new RadioGroup(null, selected)) { csection }; } else if (mType == typeof(UIImage)) { element = new ImageElement((UIImage)GetValue(mi, o)); } else if (typeof(System.Collections.IEnumerable).IsAssignableFrom(mType)) { var csection = new Section(); int count = 0; if (last_radio_index == null) { throw new Exception("IEnumerable found, but no previous int found"); } foreach (var e in (IEnumerable)GetValue(mi, o)) { csection.Add(new RadioElement(e.ToString())); count++; } var selected = (int)GetValue(last_radio_index, o); if (selected >= count || selected < 0) { selected = 0; } element = new RootElement(caption, new MemberRadioGroup(null, selected, last_radio_index)) { csection }; last_radio_index = null; } else if (typeof(int) == mType) { if (attrs.OfType <RadioSelectionAttribute>().Any()) { last_radio_index = mi; } } else { var nested = GetValue(mi, o); if (nested != null) { var newRoot = new RootElement(caption); Populate(callbacks, nested, newRoot); element = newRoot; } } if (element == null) { continue; } section.Add(element); mappings[element] = new MemberAndInstance(mi, o); } root.Add(section); }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(FloatElement obj) { return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr); }
protected void DoPageInfo() { SheetView source_report = reportPanel.Report; FpSpread source_fpspread = reportPanel.ReportSpread; source_report.PrintInfo.CopyFrom(pageReport.getReportSettings()); source_report.Rows.Count = 0; source_report.Columns.Count = 0; Dictionary <int, int> pageRowIndexs = new Dictionary <int, int>(); Dictionary <int, int> pageColumnIndexs = new Dictionary <int, int>(); while (iterator.hasNext()) { ReportPage reportPage = iterator.next() as ReportPage; float[] columns = reportPage.getColumnWidthArray(); float[] rows = reportPage.getRowHeightArray(); if (!pageColumnIndexs.ContainsKey(reportPage.getPageColumnIndex())) { pageColumnIndexs.Add(reportPage.getPageColumnIndex(), source_report.Columns.Count); source_report.Columns.Add(source_report.Columns.Count, columns.Length); for (int i = columns.Length - 1; i >= 0; i--) { source_report.Columns[source_report.Columns.Count - 1 - i].Width = columns[columns.Length - 1 - i]; } source_report.Columns[pageColumnIndexs[reportPage.getPageColumnIndex()]].PageBreak = true; } if (!pageRowIndexs.ContainsKey(reportPage.getPageRowIndex())) { pageRowIndexs.Add(reportPage.getPageRowIndex(), source_report.Rows.Count); source_report.Rows.Add(source_report.Rows.Count, rows.Length); for (int i = rows.Length - 1; i >= 0; i--) { source_report.Rows[source_report.Rows.Count - 1 - i].Height = rows[rows.Length - 1 - i]; } source_report.Rows[pageRowIndexs[reportPage.getPageRowIndex()]].PageBreak = true; } Rectangle Rect = new Rectangle(); Rect.X = pageRowIndexs[reportPage.getPageRowIndex()]; Rect.Y = pageColumnIndexs[reportPage.getPageColumnIndex()]; Rect.Width = rows.Length; Rect.Height = columns.Length; PageRectangles[reportPage.getPageRowIndex() - 1, reportPage.getPageColumnIndex() - 1] = Rect; } int FloatColumnCount = 0, FloatRowCount = 0; foreach (IElement Shape in pageReport.ToWorkSheet().DrawingContainer.ContainedObjects) { if (Shape is FloatElement) { FloatElement localFloatElement = Shape as FloatElement; Point[] arrayOfPoint = ReportHelper.calculateLastColumnAndRowOfFloatElement(pageReport.ToWorkSheet(), localFloatElement); FloatColumnCount = Math.Max(FloatColumnCount, arrayOfPoint[0].X); FloatRowCount = Math.Max(FloatRowCount, arrayOfPoint[0].Y); } } if (source_report.Columns.Count < FloatColumnCount) { source_report.Columns.Add(source_report.Columns.Count, FloatColumnCount - source_report.Columns.Count); } if (source_report.Rows.Count < FloatRowCount) { source_report.Rows.Add(source_report.Rows.Count, FloatRowCount - source_report.Rows.Count); } foreach (IElement Shape in pageReport.ToWorkSheet().DrawingContainer.ContainedObjects) { if (Shape is FloatElement) { FloatElement localFloatElement = Shape as FloatElement; FloatElement tmpfloatElement = localFloatElement.Clone() as FloatElement; tmpfloatElement.Locked = true; source_report.AddShape(tmpfloatElement); tmpfloatElement.Update(); } } }
public void InitializeSoar(SoarMSRState initialState) { if (_kernel != null) { throw new Exception("Soar: Already initialized"); } _kernel = sml.Kernel.CreateKernelInNewThread("SoarKernelSML"); if (_kernel.HadError()) { _kernel = null; throw new Exception("Soar: Error initializing kernel: " + _kernel.GetLastErrorDescription()); } _running = false; _stop = false; _agent = _kernel.CreateAgent(initialState.AgentName); // We test the kernel for an error after creating an agent as the agent // object may not be properly constructed if the create call failed so // we store errors in the kernel in this case. Once this create is done we can work directly with the agent. if (_kernel.HadError()) { throw new Exception("Soar: Error creating agent: " + _kernel.GetLastErrorDescription()); } _kernel.SetAutoCommit(false); _agent.SetBlinkIfNoChange(false); bool result = _agent.LoadProductions(initialState.Productions); if (!result) { throw new Exception("Soar: Error loading productions " + initialState.Productions + " (current working directory: " + _agent.ExecuteCommandLine("pwd") + ")"); } // reset state Bumper = new BumperState(); Override = new OverrideState(); Obstacle = false; // Prepare communication channel Identifier inputLink = _agent.GetInputLink(); if (inputLink == null) { throw new Exception("Soar: Error getting the input link"); } Identifier overrideWME = _agent.CreateIdWME(inputLink, "override"); _overrideActiveWME = _agent.CreateStringWME(overrideWME, "active", "false"); Identifier drivePowerWME = _agent.CreateIdWME(overrideWME, "drive-power"); _overrideLeftWME = _agent.CreateFloatWME(drivePowerWME, "left", 0); _overrideRightWME = _agent.CreateFloatWME(drivePowerWME, "right", 0); _overrideStopWME = _agent.CreateStringWME(drivePowerWME, "stop", "false"); Identifier configWME = _agent.CreateIdWME(inputLink, "config"); Identifier powerWME = _agent.CreateIdWME(configWME, "power"); _agent.CreateFloatWME(powerWME, "drive", initialState.DrivePower); _agent.CreateFloatWME(powerWME, "reverse", initialState.ReversePower); Identifier delayWME = _agent.CreateIdWME(configWME, "delay"); _agent.CreateFloatWME(delayWME, "stop", initialState.StopTimeout); _agent.CreateFloatWME(delayWME, "reverse", initialState.BackUpTimeout); _agent.CreateFloatWME(delayWME, "turn", initialState.TurnTimeout); _agent.CreateFloatWME(delayWME, "variance", initialState.TimeoutVariance); Identifier sensorsWME = _agent.CreateIdWME(inputLink, "sensors"); Identifier bumperWME = _agent.CreateIdWME(sensorsWME, "bumper"); Identifier frontWME = _agent.CreateIdWME(bumperWME, "front"); _frontBumperPressedWME = _agent.CreateStringWME(frontWME, "pressed", "false"); _frontBumperWasPressedWME = _agent.CreateStringWME(frontWME, "was-pressed", "false"); Identifier rearWME = _agent.CreateIdWME(bumperWME, "rear"); _rearBumperPressedWME = _agent.CreateStringWME(rearWME, "pressed", "false"); _rearBumperWasPressedWME = _agent.CreateStringWME(rearWME, "was-pressed", "false"); Identifier sickLRFWME = _agent.CreateIdWME(sensorsWME, "sicklrf"); _obstacleWME = _agent.CreateStringWME(sickLRFWME, "obstacle", "false"); // Current time WME _timeWME = _agent.CreateFloatWME(inputLink, "time", 0); // Random number WME and supporting state _randomWME = _agent.CreateFloatWME(inputLink, "random", 0); if (initialState.HasRandomSeed) { _random = new Random(initialState.RandomSeed); Trace.WriteLine("Seeding Soar's random number generator."); _agent.ExecuteCommandLine("srand " + initialState.RandomSeed); if (_agent.HadError()) { throw new Exception("Failed to seed Soar's random number generator"); } } else { _random = new Random(); } // commit input link structure _agent.Commit(); _updateCall = new sml.Kernel.UpdateEventCallback(UpdateEventCallback); _kernel.RegisterForUpdateEvent(sml.smlUpdateEventId.smlEVENT_AFTER_ALL_OUTPUT_PHASES, _updateCall, null); // spawn debugger if (initialState.SpawnDebugger) { SpawnDebugger(); } _simulationStart = DateTime.Now; OnLog("Soar initialized."); }
internal static global::System.Runtime.InteropServices.HandleRef getCPtr(FloatElement obj) { return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr; }
public Element ToElement() { MasterElement trackEntryElement = MatroskaDocTypes.TrackEntry.GetInstance(); UnsignedIntegerElement trackNumberElement = MatroskaDocTypes.TrackNumber.GetInstance(); trackNumberElement.Value = (ulong)TrackNumber; UnsignedIntegerElement trackUIDElement = MatroskaDocTypes.TrackType.GetInstance(); trackUIDElement.Value = TrackUID; UnsignedIntegerElement trackTypeElement = MatroskaDocTypes.TrackType.GetInstance(); trackTypeElement.Value = (ulong)TrackType; Utility.LogTrace($"Track type set to {TrackType.ToString()}"); UnsignedIntegerElement trackFlagEnabledElement = MatroskaDocTypes.FlagEnabled.GetInstance(); trackFlagEnabledElement.Value = (ulong)(FlagEnabled ? 1 : 0); UnsignedIntegerElement trackFlagDefaultElement = MatroskaDocTypes.FlagDefault.GetInstance(); trackFlagDefaultElement.Value = (ulong)(FlagDefault ? 1 : 0); UnsignedIntegerElement trackFlagForcedElement = MatroskaDocTypes.FlagForced.GetInstance(); trackFlagForcedElement.Value = (ulong)(FlagForced ? 1 : 0); UnsignedIntegerElement trackFlagLacingElement = MatroskaDocTypes.FlagLacing.GetInstance(); trackFlagLacingElement.Value = (ulong)(FlagLacing ? 1 : 0); UnsignedIntegerElement trackMinCacheElement = MatroskaDocTypes.MinCache.GetInstance(); trackMinCacheElement.Value = (ulong)MinCache; UnsignedIntegerElement trackMaxBlockAddIdElement = MatroskaDocTypes.MaxBlockAdditionID.GetInstance(); trackMaxBlockAddIdElement.Value = (ulong)MaxBlockAdditionalId; StringElement trackNameElement = MatroskaDocTypes.Name.GetInstance(); trackNameElement.Value = Name; StringElement trackLangElement = MatroskaDocTypes.Language.GetInstance(); trackLangElement.Value = Language; StringElement trackCodecIdElement = MatroskaDocTypes.CodecID.GetInstance(); trackCodecIdElement.Value = CodecId; trackEntryElement.AddChildElement(trackNumberElement); trackEntryElement.AddChildElement(trackUIDElement); trackEntryElement.AddChildElement(trackTypeElement); trackEntryElement.AddChildElement(trackFlagEnabledElement); trackEntryElement.AddChildElement(trackFlagDefaultElement); trackEntryElement.AddChildElement(trackFlagForcedElement); trackEntryElement.AddChildElement(trackFlagLacingElement); trackEntryElement.AddChildElement(trackMinCacheElement); trackEntryElement.AddChildElement(trackMaxBlockAddIdElement); trackEntryElement.AddChildElement(trackNameElement); trackEntryElement.AddChildElement(trackLangElement); trackEntryElement.AddChildElement(trackCodecIdElement); if (CodecPrivate != null && CodecPrivate.Length != CodecPrivate.Position) { BinaryElement trackCodecPrivateElement = MatroskaDocTypes.CodecPrivate.GetInstance(); trackCodecPrivateElement.Data = CodecPrivate; trackEntryElement.AddChildElement(trackCodecPrivateElement); } UnsignedIntegerElement trackDefaultDurationElement = MatroskaDocTypes.DefaultDuration.GetInstance(); trackDefaultDurationElement.Value = DefaultDuration; UnsignedIntegerElement trackCodecDecodeAllElement = MatroskaDocTypes.CodecDecodeAll.GetInstance(); trackCodecDecodeAllElement.Value = (ulong)(CodecDecodeAll ? 0 : 1); trackEntryElement.AddChildElement(trackDefaultDurationElement); trackEntryElement.AddChildElement(trackCodecDecodeAllElement); if (overlayUIDs.Count != 0) { foreach (ulong overlay in overlayUIDs) { UnsignedIntegerElement trackOverlayElement = MatroskaDocTypes.TrackOverlay.GetInstance(); trackOverlayElement.Value = overlay; trackEntryElement.AddChildElement(trackOverlayElement); } } // Now we add the audio/video dependant sub-elements if (this.TrackType == TrackType.Video) { MasterElement trackVideoElement = MatroskaDocTypes.Video.GetInstance(); UnsignedIntegerElement trackVideoPixelWidthElement = MatroskaDocTypes.PixelWidth.GetInstance(); trackVideoPixelWidthElement.Value = (ulong)this.video.PixelWidth; UnsignedIntegerElement trackVideoPixelHeightElement = MatroskaDocTypes.PixelHeight.GetInstance(); trackVideoPixelHeightElement.Value = (ulong)this.video.PixelHeight; UnsignedIntegerElement trackVideoDisplayWidthElement = MatroskaDocTypes.DisplayWidth.GetInstance(); trackVideoDisplayWidthElement.Value = (ulong)this.video.DisplayWidth; UnsignedIntegerElement trackVideoDisplayHeightElement = MatroskaDocTypes.DisplayHeight.GetInstance(); trackVideoDisplayHeightElement.Value = (ulong)this.video.DisplayHeight; trackVideoElement.AddChildElement(trackVideoPixelWidthElement); trackVideoElement.AddChildElement(trackVideoPixelHeightElement); trackVideoElement.AddChildElement(trackVideoDisplayWidthElement); trackVideoElement.AddChildElement(trackVideoDisplayHeightElement); trackEntryElement.AddChildElement(trackVideoElement); } else if (this.TrackType == TrackType.Audio) { MasterElement trackAudioElement = MatroskaDocTypes.Audio.GetInstance(); UnsignedIntegerElement trackAudioChannelsElement = MatroskaDocTypes.Channels.GetInstance(); trackAudioChannelsElement.Value = (ulong)this.audio.Channels; UnsignedIntegerElement trackAudioBitDepthElement = MatroskaDocTypes.BitDepth.GetInstance(); trackAudioBitDepthElement.Value = this.audio.BitDepth; FloatElement trackAudioSamplingRateElement = MatroskaDocTypes.SamplingFrequency.GetInstance(); trackAudioSamplingRateElement.Value = this.audio.SamplingFrequency; FloatElement trackAudioOutputSamplingFrequencyElement = MatroskaDocTypes.OutputSamplingFrequency.GetInstance(); trackAudioOutputSamplingFrequencyElement.Value = this.audio.OutputSamplingFrequency; trackAudioElement.AddChildElement(trackAudioChannelsElement); trackAudioElement.AddChildElement(trackAudioBitDepthElement); trackAudioElement.AddChildElement(trackAudioSamplingRateElement); trackAudioElement.AddChildElement(trackAudioOutputSamplingFrequencyElement); trackEntryElement.AddChildElement(trackAudioElement); } if (joinUIDs != null) { MasterElement trackOpElement = MatroskaDocTypes.TrackOperation.GetInstance(); MasterElement trackJoinElement = MatroskaDocTypes.TrackJoinBlocks.GetInstance(); foreach (ulong uid in joinUIDs) { UnsignedIntegerElement joinUidElement = MatroskaDocTypes.TrackJoinUID.GetInstance(); joinUidElement.Value = uid; trackJoinElement.AddChildElement(joinUidElement); } trackOpElement.AddChildElement(trackJoinElement); trackEntryElement.AddChildElement(trackOpElement); } return(trackEntryElement); }
public override void InitializeLocal(ObjectElement parentElement) { this.element = parentElement.CreateFloatElement(XStringFieldName, this.value); this.NetworkElement = element; }
private void Populate(object callbacks, object o, RootElement root) { MemberInfo last_radio_index = null; var members = o.GetType().GetMembers(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); Section section = null; foreach (var mi in members) { Type mType = GetTypeForMember(mi); if (mType == null) continue; string caption = null; object[] attrs = mi.GetCustomAttributes(false); bool skip = false; foreach (var attr in attrs) { if (attr is SkipAttribute || attr is System.Runtime.CompilerServices.CompilerGeneratedAttribute) skip = true; else if (attr is CaptionAttribute) caption = ((CaptionAttribute)attr).Caption; else if (attr is SectionAttribute) { if (section != null) root.Add(section); var sa = attr as SectionAttribute; section = new Section(sa.Caption, sa.Footer); } } if (skip) continue; if (caption == null) caption = MakeCaption(mi.Name); if (section == null) section = new Section(); Element element = null; if (mType == typeof(string)) { PasswordAttribute pa = null; AlignmentAttribute align = null; EntryAttribute ea = null; object html = null; Action invoke = null; bool multi = false; foreach (object attr in attrs) { if (attr is PasswordAttribute) pa = attr as PasswordAttribute; else if (attr is EntryAttribute) ea = attr as EntryAttribute; else if (attr is MultilineAttribute) multi = true; else if (attr is HtmlAttribute) html = attr; else if (attr is AlignmentAttribute) align = attr as AlignmentAttribute; if (attr is OnTapAttribute) { string mname = ((OnTapAttribute)attr).Method; if (callbacks == null) { throw new Exception( "Your class contains [OnTap] attributes, but you passed a null object for `context' in the constructor"); } var method = callbacks.GetType().GetMethod(mname); if (method == null) throw new Exception("Did not find method " + mname); invoke = delegate { method.Invoke(method.IsStatic ? null : callbacks, new object[0]); }; } } var value = (string)GetValue(mi, o); if (pa != null) element = new EntryElement(caption, pa.Placeholder, value, true); else if (ea != null) element = new EntryElement(caption, ea.Placeholder, value) { KeyboardType = ea.KeyboardType }; else if (multi) element = new MultilineElement(caption, value); else if (html != null) element = new HtmlElement(caption, value); else { var selement = new StringElement(caption, value); element = selement; if (align != null) selement.Alignment = align.Alignment; } if (invoke != null) (element).Tapped += invoke; } else if (mType == typeof(float)) { var floatElement = new FloatElement(null, null, (float)GetValue(mi, o)) { Caption = caption }; element = floatElement; foreach (object attr in attrs) { if (attr is RangeAttribute) { var ra = attr as RangeAttribute; floatElement.MinValue = ra.Low; floatElement.MaxValue = ra.High; floatElement.ShowCaption = ra.ShowCaption; } } } else if (mType == typeof(bool)) { bool checkbox = false; foreach (object attr in attrs) { if (attr is CheckboxAttribute) checkbox = true; } if (checkbox) element = new CheckboxElement(caption, (bool)GetValue(mi, o)); else element = new BooleanElement(caption, (bool)GetValue(mi, o)); } else if (mType == typeof(DateTime)) { var dateTime = (DateTime)GetValue(mi, o); bool asDate = false, asTime = false; foreach (object attr in attrs) { if (attr is DateAttribute) asDate = true; else if (attr is TimeAttribute) asTime = true; } if (asDate) element = new DateElement(caption, dateTime); else if (asTime) element = new TimeElement(caption, dateTime); else element = new DateTimeElement(caption, dateTime); } else if (mType.IsEnum) { var csection = new Section(); ulong evalue = Convert.ToUInt64(GetValue(mi, o), null); int idx = 0; int selected = 0; foreach (var fi in mType.GetFields(BindingFlags.Public | BindingFlags.Static)) { ulong v = Convert.ToUInt64(GetValue(fi, null)); if (v == evalue) selected = idx; var ca = Attribute.GetCustomAttribute(fi, typeof(CaptionAttribute)) as CaptionAttribute; csection.Add(new RadioElement(ca != null ? ca.Caption : MakeCaption(fi.Name))); idx++; } element = new RootElement(caption, new RadioGroup(null, selected)) { csection }; } else if (mType == typeof(UIImage)) { element = new ImageElement((UIImage)GetValue(mi, o)); } else if (typeof(System.Collections.IEnumerable).IsAssignableFrom(mType)) { var csection = new Section(); int count = 0; if (last_radio_index == null) throw new Exception("IEnumerable found, but no previous int found"); foreach (var e in (IEnumerable)GetValue(mi, o)) { csection.Add(new RadioElement(e.ToString())); count++; } var selected = (int)GetValue(last_radio_index, o); if (selected >= count || selected < 0) selected = 0; element = new RootElement(caption, new MemberRadioGroup(null, selected, last_radio_index)) { csection }; last_radio_index = null; } else if (typeof(int) == mType) { if (attrs.OfType<RadioSelectionAttribute>().Any()) { last_radio_index = mi; } } else { var nested = GetValue(mi, o); if (nested != null) { var newRoot = new RootElement(caption); Populate(callbacks, nested, newRoot); element = newRoot; } } if (element == null) continue; section.Add(element); mappings[element] = new MemberAndInstance(mi, o); } root.Add(section); }
public override void AddFromRemote(Element element) { this.NetworkElement = element; this.element = FloatElement.Cast(element); this.value = this.element.GetValue(); }
public void InitializeSoar(SoarMSRState initialState) { if (_kernel != null) { throw new Exception("Soar: Already initialized"); } _kernel = sml.Kernel.CreateKernelInNewThread("SoarKernelSML"); if (_kernel.HadError()) { _kernel = null; throw new Exception("Soar: Error initializing kernel: " + _kernel.GetLastErrorDescription()); } _running = false; _stop = false; _agent = _kernel.CreateAgent(initialState.AgentName); // We test the kernel for an error after creating an agent as the agent // object may not be properly constructed if the create call failed so // we store errors in the kernel in this case. Once this create is done we can work directly with the agent. if (_kernel.HadError()) throw new Exception("Soar: Error creating agent: " + _kernel.GetLastErrorDescription()); _kernel.SetAutoCommit(false); _agent.SetBlinkIfNoChange(false); bool result = _agent.LoadProductions(initialState.Productions); if (!result) { throw new Exception("Soar: Error loading productions " + initialState.Productions + " (current working directory: " + _agent.ExecuteCommandLine("pwd") + ")"); } // reset state Bumper = new BumperState(); Override = new OverrideState(); Obstacle = false; // Prepare communication channel Identifier inputLink = _agent.GetInputLink(); if (inputLink == null) throw new Exception("Soar: Error getting the input link"); Identifier overrideWME = _agent.CreateIdWME(inputLink, "override"); _overrideActiveWME = _agent.CreateStringWME(overrideWME, "active", "false"); Identifier drivePowerWME = _agent.CreateIdWME(overrideWME, "drive-power"); _overrideLeftWME = _agent.CreateFloatWME(drivePowerWME, "left", 0); _overrideRightWME = _agent.CreateFloatWME(drivePowerWME, "right", 0); _overrideStopWME = _agent.CreateStringWME(drivePowerWME, "stop", "false"); Identifier configWME = _agent.CreateIdWME(inputLink, "config"); Identifier powerWME = _agent.CreateIdWME(configWME, "power"); _agent.CreateFloatWME(powerWME, "drive", initialState.DrivePower); _agent.CreateFloatWME(powerWME, "reverse", initialState.ReversePower); Identifier delayWME = _agent.CreateIdWME(configWME, "delay"); _agent.CreateFloatWME(delayWME, "stop", initialState.StopTimeout); _agent.CreateFloatWME(delayWME, "reverse", initialState.BackUpTimeout); _agent.CreateFloatWME(delayWME, "turn", initialState.TurnTimeout); _agent.CreateFloatWME(delayWME, "variance", initialState.TimeoutVariance); Identifier sensorsWME = _agent.CreateIdWME(inputLink, "sensors"); Identifier bumperWME = _agent.CreateIdWME(sensorsWME, "bumper"); Identifier frontWME = _agent.CreateIdWME(bumperWME, "front"); _frontBumperPressedWME = _agent.CreateStringWME(frontWME, "pressed", "false"); _frontBumperWasPressedWME = _agent.CreateStringWME(frontWME, "was-pressed", "false"); Identifier rearWME = _agent.CreateIdWME(bumperWME, "rear"); _rearBumperPressedWME = _agent.CreateStringWME(rearWME, "pressed", "false"); _rearBumperWasPressedWME = _agent.CreateStringWME(rearWME, "was-pressed", "false"); Identifier sickLRFWME = _agent.CreateIdWME(sensorsWME, "sicklrf"); _obstacleWME = _agent.CreateStringWME(sickLRFWME, "obstacle", "false"); // Current time WME _timeWME = _agent.CreateFloatWME(inputLink, "time", 0); // Random number WME and supporting state _randomWME = _agent.CreateFloatWME(inputLink, "random", 0); if (initialState.HasRandomSeed) { _random = new Random(initialState.RandomSeed); Trace.WriteLine("Seeding Soar's random number generator."); _agent.ExecuteCommandLine("srand " + initialState.RandomSeed); if (_agent.HadError()) { throw new Exception("Failed to seed Soar's random number generator"); } } else { _random = new Random(); } // commit input link structure _agent.Commit(); _updateCall = new sml.Kernel.UpdateEventCallback(UpdateEventCallback); _kernel.RegisterForUpdateEvent(sml.smlUpdateEventId.smlEVENT_AFTER_ALL_OUTPUT_PHASES, _updateCall, null); // spawn debugger if (initialState.SpawnDebugger) { SpawnDebugger(); } _simulationStart = DateTime.Now; OnLog("Soar initialized."); }