private StepDataObject ExtractFileName(iso_10303 iso10303) { if (iso10303 == null) { throw new ArgumentNullException("iso10303"); } iso_10303_28_header header = iso10303.iso_10303_28_header; if (header == null) { throw new ArgumentNullException("iso10303.iso_10303_28_header"); } StepDataObject sdo = new StepDataObject(); sdo.ObjectName = "FILE_NAME"; sdo.Properties.Add(StepValue.CreateString(header.name)); sdo.Properties.Add(StepValue.CreateDate(header.time_stamp)); sdo.Properties.Add(StepValue.CreateArray(StepValue.CreateString(header.author))); //FIXME header.organization is a string and not a list, but the Step file expects an array sdo.Properties.Add(StepValue.CreateArray(StepValue.CreateString(header.organization))); sdo.Properties.Add(StepValue.CreateString(header.preprocessor_version)); sdo.Properties.Add(StepValue.CreateString(header.originating_system)); sdo.Properties.Add(StepValue.CreateString(header.authorization)); return(sdo); }
public static StepFile simpleStepRepresentation() { StepDataObject entity0 = new StepDataObject("IFCPROJECT", StepValue.CreateString("3MD_HkJ6X2EwpfIbCFm0g_"), StepValue.CreateLineReference(2), StepValue.CreateString("Default Project"), StepValue.CreateString("Description of Default Project"), StepValue.CreateNull(), StepValue.CreateFloat(-22.4), StepValue.CreateNull(), StepValue.CreateArray( StepValue.CreateLineReference(20) ), StepValue.CreateLineReference(7) ); StepDataObject entity1 = new StepDataObject("IFCOWNERHISTORY", StepValue.CreateLineReference(3), StepValue.CreateNestedEntity(new StepDataObject("IFCTEXT", StepValue.CreateString("foobar"))), StepValue.CreateNull(), StepValue.CreateEnum("ADDED"), StepValue.CreateNull(), StepValue.CreateBoolean(false), StepValue.CreateOverridden(), StepValue.CreateInteger(1217620436) ); StepFile sf = new StepFile(); appendHeaderToStepFile(sf, createHeader()); sf.Data.Add(1, entity0); sf.Data.Add(2, entity1); return(sf); }
/// <summary> /// Processes the value changes and emits the appropriate events. /// </summary> public virtual void Process() { if (!isActiveAndEnabled) { return; } if (!Value.ApproxEquals(previousValue)) { previousValue = Value; EmitValueChanged(); EmitNormalizedValueChanged(); } if (!StepValue.ApproxEquals(previousStepValue)) { previousStepValue = StepValue; EmitStepValueChanged(); } float targetValue = GetTargetValue(); bool targetValueReached = NormalizedValue.ApproxEquals(targetValue, targetValueReachedThreshold); bool shouldEmitEvent = !previousTargetValueReached && targetValueReached; previousTargetValueReached = targetValueReached; if (CanMoveToTargetValue() && shouldEmitEvent) { EmitTargetValueReached(); } }
/// <summary> /// Asserts a StepValue is an array and is not null, but does not assert anything of the array contents /// </summary> /// <param name="actual"></param> public void AssertArray(StepValue actual) { Assert.IsNotNull(actual); Assert.AreEqual(StepToken.StartArray, actual.Token); Assert.AreEqual(typeof(List <StepValue>), actual.ValueType); Assert.IsNotNull(actual.Value); }
private static StepValue CompareDepth(StepValue current, StepValue candidate) { if (current.Depth > candidate.Depth) { return(candidate); } return(current); }
/// <summary> /// Información de depuración /// </summary> protected override string GetDebugInfo(int indent) { return(Environment.NewLine + base.GetIndent(indent) + " Variable: " + IndexVariable.GetDebugInfo() + " StartValue: " + StartValue.GetDebugInfo() + " StartValueRPN: " + StartValueRPN.GetDebugInfo() + " EndValue: " + EndValue.GetDebugInfo() + " EndValueRPN: " + EndValueRPN.GetDebugInfo() + " StepValue: " + StepValue.GetDebugInfo() + " StepValueRPN: " + StepValueRPN.GetDebugInfo()); }
public void AssertArray(int expectedCount, StepValue actual) { AssertArray(actual); List <StepValue> array = actual.Value as List <StepValue>; Assert.IsNotNull(array); Assert.AreEqual(expectedCount, array.Count); }
private StepValue deserializeNestedEntity(IStepReader reader) { if (reader == null) { throw new ArgumentNullException("reader"); } return(StepValue.CreateNestedEntity(deserializeEntity(reader))); }
/// <summary> /// Checks if the <see cref="StepValue"/> has changed. /// </summary> protected virtual void CheckStepValueChange() { if (!StepValue.ApproxEquals(previousStepValue)) { previousStepValue = StepValue; EmitStepValueChanged(); } }
/// <summary> /// Creates the file description step data object. /// This is the same for all STEP files. /// </summary> /// <returns></returns> private StepDataObject GenerateFileDescription( ) { return(new StepDataObject("FILE_DESCRIPTION", StepValue.CreateArray( StepValue.CreateString("ViewDefinition [CoordinationView, QuantityTakeOffAddOnView]") ), StepValue.CreateString("2;1") )); }
private StepDataObject ExtractFileSchema(iso_10303 iso10303) { if (iso10303 == null) { throw new ArgumentNullException("iso10303"); } StepDataObject sdo = new StepDataObject(); sdo.ObjectName = "FILE_SCHEMA"; sdo.Properties.Add(StepValue.CreateArray(StepValue.CreateString("IFC2X3"))); return(sdo); }
private static StepValue EvaluateMin(StepValue current, StepValue candidate, bool random = false) { if (current.Value > candidate.Value) { return(candidate); } if (random && current.Value == candidate.Value) { return(RandomMove(current, candidate)); } return(current); }
private static StepValue RandomMove(StepValue current, StepValue candidate) { Random rand = new Random(); if (rand.NextDouble() >= 0.5) { return(candidate); } else { return(current); } }
private StepValue ExtractProperty(Object entity, PropertyInfo pi) { if (entity == null) { throw new ArgumentNullException("entity"); } if (pi == null) { throw new ArgumentNullException("pi"); } logger.Debug(String.Format(CultureInfo.InvariantCulture, "Method ExtractProperty(Object, PropertyInfo) called with parameters 'entity', an object of type {0}, and 'pi', a PropertyInfo of name '{1}' and PropertyType {2}", entity.GetType().FullName, pi.Name, pi.PropertyType)); if (pi.Name == "ValueAsString") { throw new StepBindingException("Property extraction has gone wrong - it should not be working with any properties named 'ValueAsString'"); } if (IsOverriddenProperty(pi)) { return(StepValue.CreateOverridden()); } object value = pi.GetValue(entity, null); if (value == null) { return(StepValue.CreateNull()); } if (IsIndirectProperty(pi)) { return(ExtractProperty(value, GetIndirectProperty(pi.PropertyType))); //TODO what if this is indexed?? } if (pi.PropertyType == typeof(object)) { //TODO /* * The value should be wrapped as an object * e.g. IFCMEASUREWITHUNIT(1.745E-2, ... * should become * IFCMEASUREWITHUNIT(IFCPLANEANGLEMEASURE(1.745E-2), ... * * **/ logger.Debug(String.Format("\t\tFound an object property. Type of value is {0}", value.GetType())); return(StepValue.CreateNestedEntity(ExtractObject(value))); } return(ExtractPropertyValue(value)); }
public object Clone() { StepValue result = new StepValue(); result.Project = this.Project; result.OutValue = this.OutValue; result.Value = this.Value; result.ValueTwo = this.ValueTwo; result.ValueOther = this.ValueOther; result.Time = this.Time; result.Active = this.Active; result.Result = this.Result; return(result); }
protected override bool Persist(IPersistence persistence, ref ePersistence phase) { base.Persist(persistence, ref phase); switch (phase) { case ePersistence.Initial: persistence.UpsertField(Constants.IntVariable_Value, _Value.ToString()); persistence.UpsertField(Constants.IntVariable_MinValue, MinValue.ToString()); persistence.UpsertField(Constants.IntVariable_MaxValue, MaxValue.ToString()); persistence.UpsertField(Constants.IntVariable_StepValue, StepValue.ToString()); break; } return(true); }
public override void WriteXml(XmlWriter writer) { base.WriteXml(writer); writer.WriteElementString("KnobImage", KnobImage); writer.WriteElementString("RotationStep", RotationStep.ToString(CultureInfo.InvariantCulture)); writer.WriteElementString("StepValue", StepValue.ToString(CultureInfo.InvariantCulture)); writer.WriteElementString("InitialRotation", InitialRotation.ToString(CultureInfo.InvariantCulture)); writer.WriteStartElement("ClickType"); writer.WriteElementString("Type", ClickType.ToString()); if (ClickType != ClickType.Touch) { writer.WriteElementString("Sensitivity", Sensitivity.ToString(CultureInfo.InvariantCulture)); } writer.WriteEndElement(); }
private StepValue AlphaBetaSearch(int[,] currentMove, int depth, bool isComputer, StepValue alpha, StepValue beta) { StepValue best, result; int finished = this.IsGameFinished(currentMove); if (finished != NotFinished) { return(new StepValue(depth, finished, currentMove)); } if (isComputer) { best = new StepValue(0, Int32.MinValue, board); foreach (var move in GetMoves(Player1, currentMove)) { result = AlphaBetaSearch(move, depth + 1, false, alpha, beta); best = EvaluateMax2(best, new StepValue(depth, result.Value, move)); alpha = EvaluateMax2(alpha, best); if (beta <= alpha) { break; } } return(best); } else { best = new StepValue(0, Int32.MaxValue, board); foreach (var move in GetMoves(Player2, currentMove)) { result = AlphaBetaSearch(move, depth + 1, true, alpha, beta); best = EvaluateMin2(best, new StepValue(depth, result.Value, move)); beta = EvaluateMin2(beta, best); if (beta <= alpha) { break; } } return(best); } }
/// <summary> /// Maps a STEP float to .Net System.Double /// </summary> /// <param name="pi"></param> /// <param name="obj"></param> /// <param name="sv"></param> private void mapFloat(PropertyInfo pi, ref Object obj, StepValue sv) { if (pi == null) { throw new ArgumentNullException("pi"); } if (obj == null) { throw new ArgumentNullException("obj"); } if (!(sv.Value is double)) { throw new ArgumentException("sv.Value cannot be cast to a double"); } pi.SetValue(obj, (double)sv.Value, null); }
/// <summary> /// Maps a STEP integer to a .Net System.Int32 /// </summary> /// <param name="pi"></param> /// <param name="obj"></param> /// <param name="sv"></param> private void mapInteger(PropertyInfo pi, ref Object obj, StepValue sv) { if (pi == null) { throw new ArgumentNullException("pi"); } if (obj == null) { throw new ArgumentNullException("obj"); } if (!(sv.Value is int)) { throw new ArgumentException("sv.Value cannot be cast to an int"); } pi.SetValue(obj, (int)sv.Value, null); }
/// <summary> /// Populates a .Net instance's properties with the data given in the Step Data Object /// </summary> /// <param name="obj">The empty .Net instance which will be populated</param> /// <param name="sdoId">The unique Id of the StepDataObject</param> /// <param name="sdo">The Step Data Object with data to inject into the .Net object</param> /// <param name="typeProperties">The type properties applicable to the .Net instance</param> private void populateObject(ref Object obj, int sdoId, StepDataObject sdo, IList <PropertyInfo> typeProperties) { if (obj == null) { throw new ArgumentNullException("obj"); } if (typeProperties == null || typeProperties.Count < 1) { throw new ArgumentNullException("typeProperties"); } if (sdo == null) { throw new ArgumentNullException("sdo"); } if (sdo.Properties == null) { throw new ArgumentException("sdo.Properties is null"); } if (sdo.Properties.Count != typeProperties.Count) { throw new StepBindingException(String.Format(CultureInfo.InvariantCulture, "The number of data values, {0}, provided by the STEP data object, {1}, does not equal the number of properties, {2}, available in the .Net object, {3}", sdo.Properties.Count, sdo.ObjectName, typeProperties.Count, obj.GetType().FullName)); } for (int propertyIndex = 0; propertyIndex < sdo.Properties.Count; propertyIndex++) { StepValue sv = sdo.Properties[propertyIndex]; PropertyInfo pi = typeProperties[propertyIndex]; if (pi == null) { throw new StepBindingException(String.Format(CultureInfo.InvariantCulture, "A null property was found at index {0} of the cached properties provided for type {1}", propertyIndex, obj.GetType().Name)); } populateProperty(pi, ref obj, sv, sdoId); } }
public static StepValue <IEnumerable <dynamic> > CsvToDynamic(this StepValue <Stream> value, string delimiter) { using (var sr = new StreamReader(value.Value, System.Text.Encoding.GetEncoding("ISO-8859-1"))) { using (var csv = new CsvReader(sr, new Configuration { Delimiter = delimiter, BadDataFound = _ => { var a = _.ToString(); } })) { var records = csv.GetRecords <dynamic>().ToList(); return(new StepValue <IEnumerable <dynamic> >(records, value)); } } }
public override void WriteXml(XmlWriter writer) { base.WriteXml(writer); writer.WriteElementString("BGPlateImage", BGPlateImage); writer.WriteElementString("KnobImage", KnobImage); writer.WriteElementString("Needle_Scale", Needle_Scale.ToString(CultureInfo.InvariantCulture)); writer.WriteElementString("Needle_PosX", Needle_PosX.ToString(CultureInfo.InvariantCulture)); writer.WriteElementString("Needle_PosY", Needle_PosY.ToString(CultureInfo.InvariantCulture)); writer.WriteElementString("Needle_PivotX", Needle_PivotX.ToString(CultureInfo.InvariantCulture)); writer.WriteElementString("Needle_PivotY", Needle_PivotY.ToString(CultureInfo.InvariantCulture)); writer.WriteElementString("InitialValue", InitialValue.ToString(CultureInfo.InvariantCulture)); writer.WriteElementString("StepValue", StepValue.ToString(CultureInfo.InvariantCulture)); writer.WriteElementString("MaxValue", MaxValue.ToString(CultureInfo.InvariantCulture)); writer.WriteElementString("MinValue", MinValue.ToString(CultureInfo.InvariantCulture)); writer.WriteElementString("InitialRotation", InitialRotation.ToString(CultureInfo.InvariantCulture)); writer.WriteElementString("RotationTravel", RotationTravel.ToString(CultureInfo.InvariantCulture)); }
public override void WriteXml(XmlWriter writer) { base.WriteXml(writer); writer.WriteElementString("KnobImage", KnobImage); writer.WriteElementString("InitialValue", InitialValue.ToString(CultureInfo.InvariantCulture)); writer.WriteElementString("StepValue", StepValue.ToString(CultureInfo.InvariantCulture)); writer.WriteElementString("MaxValue", MaxValue.ToString(CultureInfo.InvariantCulture)); writer.WriteElementString("MinValue", MinValue.ToString(CultureInfo.InvariantCulture)); writer.WriteElementString("InitialRotation", InitialRotation.ToString(CultureInfo.InvariantCulture)); writer.WriteElementString("RotationTravel", RotationTravel.ToString(CultureInfo.InvariantCulture)); writer.WriteStartElement("ClickType"); writer.WriteElementString("Type", ClickType.ToString()); if (ClickType == Controls.ClickType.Swipe) { writer.WriteElementString("Sensitivity", SwipeSensitivity.ToString(CultureInfo.InvariantCulture)); } writer.WriteEndElement(); }
private StepValue EvaluateMin2(StepValue current, StepValue candidate, bool random = false) { if (current.Value > candidate.Value) { return(candidate); } if (current.Value == candidate.Value && current.Depth != candidate.Depth) { return(CompareDepth(current, candidate)); } if (random && current.Value == candidate.Value) { return(RandomMove(current, candidate)); } return(current); }
/// <summary> /// Maps a STEP string to a .Net System.String /// </summary> /// <param name="pi"></param> /// <param name="obj"></param> /// <param name="sv"></param> private void mapString(PropertyInfo pi, ref Object obj, StepValue sv) { if (pi == null) { throw new ArgumentNullException("pi"); } if (obj == null) { throw new ArgumentNullException("obj"); } if (sv.Value == null) { throw new ArgumentNullException("sv.Value"); } if (!(sv.Value is string)) { throw new ArgumentException("sv.Value is not of type String"); } pi.SetValue(obj, (string)sv.Value, null); }
public virtual void Process() { if (wasDisabled || !Value.ApproxEquals(previousValue)) { if (!isMoving && previousValue < float.MaxValue) { EmitStartedMoving(); isMoving = true; } previousValue = Value; EmitValueChanged(); EmitNormalizedValueChanged(); } else { if (isMoving) { EmitStoppedMoving(); isMoving = false; } } if (!StepValue.ApproxEquals(previousStepValue)) { previousStepValue = StepValue; EmitStepValueChanged(); } float targetValue = GetTargetValue(); bool targetValueReached = NormalizedValue.ApproxEquals(targetValue, TargetValueReachedThreshold); bool shouldEmitEvent = !previousTargetValueReached && targetValueReached; previousTargetValueReached = targetValueReached; if (CanMoveToTargetValue() && shouldEmitEvent) { EmitTargetValueReached(); } wasDisabled = false; }
/// <summary> /// Maps a STEP entity to a .Net object /// </summary> /// <param name="pi"></param> /// <param name="obj"></param> /// <param name="sv"></param> private void mapObject(PropertyInfo pi, ref Object obj, StepValue sv) { if (pi == null) { throw new ArgumentNullException("pi"); } if (obj == null) { throw new ArgumentNullException("obj"); } if (sv.Value == null) { throw new ArgumentNullException("sv.Value"); } StepDataObject sdo = sv.Value as StepDataObject; if (sdo == null) { throw new ArgumentException("sv.Value is not of type StepDataObject"); } Object nestedObj = bindObject(-1, sdo); //as a quirk of the automatically generated schema //nested properties are wrapped in an intermediate class. Object wrappingObj = Activator.CreateInstance(pi.PropertyType); logger.Debug("Attempting to find \"Item\" property for type of " + pi.PropertyType); PropertyInfo wrappingProp = pi.PropertyType.GetProperty("Item", BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance); if (wrappingProp == null) { throw new StepBindingException("Could not find a suitable property in the wrapping class around a nested object"); } wrappingProp.SetValue(wrappingObj, nestedObj, null); //now insert the wrapping object pi.SetValue(obj, wrappingObj, null); }
private StepValue MiniMax(int [,] currentMove, int depth, bool isComputer) { StepValue best, value; int finished = this.IsGameFinished(currentMove); if (finished != NotFinished) { return(new StepValue(depth, finished, currentMove)); } if (isComputer) { best = new StepValue(0, Int32.MinValue, board); foreach (var move in GetMoves(Player1, currentMove)) { value = MiniMax(move, depth + 1, false); best = EvaluateMax(best, new StepValue(depth, value.Value, move), true); } return(best); } else { best = new StepValue(0, Int32.MaxValue, board); foreach (var move in GetMoves(Player2, currentMove)) { value = MiniMax(move, depth + 1, true); best = EvaluateMin(best, new StepValue(depth, value.Value, move), true); } return(best); } }
public Caret(IUIStyle style, TView textInformation) : base(style) { if (textInformation == null) { throw new ArgumentNullException(nameof(textInformation)); } styleDefinition = StyleSystem.StylesFor <TextStyleDefinition>(); TextInformation = textInformation; TextInformation.Document.DocumentModified += UpdatePositions; startPosition = null; endPosition = TextInformation.Document.CreatePosition(0, Bias.Backward); selectionHighlight = new Highlight <TDocument>(startPosition, endPosition, Style); textInformation.Highlighter.AddHighlight(selectionHighlight); blinkAnimation = new StepValue(0, 1) { Duration = 1, Loop = AnimationLoop.Loop }; Style.ValueChanged += OnStyleChanged; }