/// <summary>Removeve property from list.</summary> /// <param name="propertyToRemove">The property to remove.</param> public void RemoveProperty(PresentedProperties propertyToRemove) { if (this.PropertiesList.Contains(propertyToRemove)) { this.PropertiesList.Remove(propertyToRemove); } }
/// <summary>The value of objects property (report or UDA), returned in units given in PresentedProperties propertyType.</summary> /// <param name="thisPart">The object for which to get amount.</param> /// <param name="property">The property to get the value for.</param> /// <param name="presentedPropertiesInstance">The Presented Properties Instance.</param> /// <returns>Value of objects property. If both UDA and Report properties are declared, returns value of report property.</returns> public static object GetPartPropertyValue(ModelObject thisPart, PresentedProperties property, PresentedPropertiesXml presentedPropertiesInstance) { var isReportProperty = !string.IsNullOrEmpty(property.ReportPropertyName); var propertvalueY = GetPropertvalueYBasedOnType( presentedPropertiesInstance, thisPart, property, isReportProperty); try { switch (GetBaseType(property.PropertyType)) { case PropertyTypes.Int: return(string.IsNullOrEmpty(propertvalueY) ? 0 : Convert.ToInt32(propertvalueY)); case PropertyTypes.String: return(propertvalueY); case PropertyTypes.Date: return(string.IsNullOrEmpty(propertvalueY) ? null : (object)Convert.ToDateTime(propertvalueY)); default: return(string.IsNullOrEmpty(propertvalueY) ? 0.0 : Convert.ToDouble(propertvalueY)); } } catch (Exception ee) { Debug.WriteLine(ee); } return(null); }
/// <summary>Add a property to presented properties list. Sets property visible name same as ReportPropertyName /// and tries to deduct the type based on ValueString.</summary> /// <param name="reportPropertyName">Tekla Structures report property name.</param> /// <param name="valueString">Value of the report property.</param> /// <returns>If property with same visible name already exits, property is not added and <c>false.</c> is returned. /// Otherwise <c>true.</c>.</returns> public bool AddPropertyWithReportName(string reportPropertyName, string valueString) { var result = false; PresentedProperties newProperty = null; var addType = PresentedPropertiesManage.PropertyTypes.String; // Hack for inquiry-copy if (!string.IsNullOrEmpty(valueString)) { addType = TryToGuessType(valueString); } if (!this.GetPropertyByName(reportPropertyName, ref newProperty)) { newProperty = new PresentedProperties( reportPropertyName, reportPropertyName, string.Empty, addType, 2, PresentedProperties.DefaultWidth, true); this.PropertiesList.Add(newProperty); result = true; } return(result); }
/// <summary>Copy all attributes from other property.</summary> /// <param name="propertyToCopy">Presented property from which attributes are copied from.</param> public void Copy(PresentedProperties propertyToCopy) { this.name = propertyToCopy.Name; this.reportPropertyName = propertyToCopy.ReportPropertyName; this.udaPropertyName = propertyToCopy.UdaPropertyName; this.propertyType = propertyToCopy.PropertyType; this.displayType = propertyToCopy.DisplayType; this.decimals = propertyToCopy.Decimals; this.width = propertyToCopy.Width; this.hidden = propertyToCopy.Hidden; }
/// <summary>The value of objects property (report or UDA), returned in units given in PresentedProperties propertyType.</summary> /// <param name="thisPart">The object for which to get amount.</param> /// <param name="visibleName">Name of the property is properties xml file.</param> /// <param name="presentedPropertiesInstance">The Presented Properties Instance.</param> /// <returns>Value of objects property. If both UDA and Report properties are declared, returns value of report property.</returns> public static object GetPartPropertyValue(ModelObject thisPart, string visibleName, PresentedPropertiesXml presentedPropertiesInstance) { object result = null; PresentedProperties thisProperty = null; if (presentedPropertiesInstance.GetPropertyByName(visibleName, ref thisProperty)) { result = GetPartPropertyValue(thisPart, thisProperty, presentedPropertiesInstance); } return(result); }
/// <summary>Moves property to different place in list.</summary> /// <param name="propertyToMove">The property to move.</param> /// <param name="propertyToMoveBy">The property to move by.</param> public void MoveProperty(PresentedProperties propertyToMove, PresentedProperties propertyToMoveBy) { var copyProperty = new PresentedProperties(propertyToMove); this.PropertiesList.Remove(propertyToMove); if (propertyToMoveBy != null) { this.PropertiesList.Insert(this.PropertiesList.IndexOf(propertyToMoveBy), copyProperty); } else { this.PropertiesList.Add(copyProperty); } }
/// <summary>Gets property from property list by name, if not found, try to get by model property name.</summary> /// <param name="propertyName">Name of the property.</param> /// <param name="property">The property.</param> /// <returns>True if found.</returns> public bool GetPropertyByNameOrModelPropertyName(string propertyName, ref PresentedProperties property) { var result = false; if (this.GetPropertyByName(propertyName, ref property)) { result = true; } else if (this.GetPropertyByModelPropertyName(propertyName, ref property)) { result = true; } return(result); }
/// <summary>Gets property from property list by name.</summary> /// <param name="propertyName">Name of the property.</param> /// <param name="property">The property.</param> /// <returns>True if found.</returns> public bool GetPropertyByName(string propertyName, ref PresentedProperties property) { var result = false; if (!string.IsNullOrEmpty(propertyName)) { foreach (var propertyInList in this.PropertiesList.Where(propertyInList => propertyInList.Name == propertyName)) { property = propertyInList; result = true; } } return(result); }
/// <summary> /// Creates the default file. /// </summary> private void CreateDefaultFile() { var defaults = CsIniDefaultAttributes.Split('|'); this.propertiesList = new SearchableSortableBindingList <PresentedProperties>(); foreach (var property in defaults) { var splitChar = new char[1]; splitChar[0] = ' '; var tmpProperty = property.Split(splitChar, StringSplitOptions.RemoveEmptyEntries); if (tmpProperty.Length <= 0) { continue; } var defaultProp = new PresentedProperties( tmpProperty[0], tmpProperty[0], string.Empty, tmpProperty[7], 2, PresentedProperties.DefaultWidth, false); this.propertiesList.Add(defaultProp); } // Example of formula var formulaExample = new PresentedProperties( "Rebar Group Weight", "WEIGHT * NUMBER", string.Empty, "calc", 2, PresentedProperties.DefaultWidth, false); this.propertiesList.Add(formulaExample); this.XmlWriteProperties(this.propertiesList); }
/// <summary>The get property value based on type.</summary> /// <param name="presentedPropertiesInstance">The presented properties instance.</param> /// <param name="part">The part value.</param> /// <param name="thisProperty">The this property.</param> /// <param name="isReportProperty">The is report property.</param> /// <param name="roundDoubles">The round doubles.</param> /// <returns>The System.String.</returns> private static string GetPropertvalueYBasedOnType( PresentedPropertiesXml presentedPropertiesInstance, ModelObject part, PresentedProperties thisProperty, bool isReportProperty, bool roundDoubles = true) { var type = thisProperty.PropertyType; var decimals = thisProperty.Decimals; var propertyName = thisProperty.ReportPropertyName; if (!isReportProperty) { propertyName = thisProperty.UdaPropertyName; } var result = string.Empty; var intValue = 0; var doubleValue = 0.0; var stringValue = string.Empty; var baseDate = new DateTime(1970, 1, 1); var doubleFromat = roundDoubles ? "N" + decimals.ToString(CultureInfo.InvariantCulture) : "G"; switch (type.ToLower()) { case PropertyTypes.Pieces: result = "1"; break; case PropertyTypes.Formula: if (GetAttributeByUDAFormula(presentedPropertiesInstance, part, propertyName, out doubleValue)) { result = doubleValue.ToString(doubleFromat); } break; case PropertyTypes.Int: GetProperty(part, propertyName, isReportProperty, ref intValue); result = intValue.ToString(CultureInfo.InvariantCulture); break; case PropertyTypes.Mm: case PropertyTypes.Mm2: case PropertyTypes.Mm3: case PropertyTypes.Double: GetProperty(part, propertyName, isReportProperty, ref doubleValue); result = doubleValue.ToString(doubleFromat); break; case PropertyTypes.String: GetProperty(part, propertyName, isReportProperty, ref stringValue); result = stringValue; break; case PropertyTypes.Date: if (!propertyName.StartsWith("EXTERNAL.")) { GetProperty(part, propertyName, isReportProperty, ref intValue); if (intValue != 0) { baseDate = baseDate.AddSeconds(intValue); result = baseDate.ToString(CultureInfo.InvariantCulture); } } else { GetProperty(part, propertyName, isReportProperty, ref stringValue); result = stringValue; } break; case PropertyTypes.Kg: GetProperty(part, propertyName, isReportProperty, ref doubleValue); result = doubleValue.ToString(doubleFromat); break; case PropertyTypes.Ton: GetProperty(part, propertyName, isReportProperty, ref doubleValue); doubleValue = doubleValue / 1000; result = doubleValue.ToString(doubleFromat); break; case PropertyTypes.Cm: GetProperty(part, propertyName, isReportProperty, ref doubleValue); doubleValue = doubleValue / 10; result = doubleValue.ToString(doubleFromat); break; case PropertyTypes.M: GetProperty(part, propertyName, isReportProperty, ref doubleValue); doubleValue = doubleValue / 1000; result = doubleValue.ToString(doubleFromat); break; case PropertyTypes.Cm2: GetProperty(part, propertyName, isReportProperty, ref doubleValue); doubleValue = doubleValue / 100; result = doubleValue.ToString(doubleFromat); break; case PropertyTypes.M2: GetProperty(part, propertyName, isReportProperty, ref doubleValue); doubleValue = doubleValue / 1000000; result = doubleValue.ToString(doubleFromat); break; case PropertyTypes.Cm3: GetProperty(part, propertyName, isReportProperty, ref doubleValue); doubleValue = doubleValue / 1000; result = doubleValue.ToString(doubleFromat); break; case PropertyTypes.M3: GetProperty(part, propertyName, isReportProperty, ref doubleValue); doubleValue = doubleValue / 1000000000; result = doubleValue.ToString(doubleFromat); break; case PropertyTypes.Inch: GetProperty(part, propertyName, isReportProperty, ref doubleValue); doubleValue = doubleValue / 25.4; result = doubleValue.ToString(doubleFromat); break; case PropertyTypes.Inch2: GetProperty(part, propertyName, isReportProperty, ref doubleValue); doubleValue = doubleValue / 645.16; result = doubleValue.ToString(doubleFromat); break; case PropertyTypes.Inch3: GetProperty(part, propertyName, isReportProperty, ref doubleValue); doubleValue = doubleValue / 16387.064; result = doubleValue.ToString(doubleFromat); break; case PropertyTypes.Ft: GetProperty(part, propertyName, isReportProperty, ref doubleValue); doubleValue = doubleValue / 304.8; result = doubleValue.ToString(doubleFromat); break; case PropertyTypes.Ft2: GetProperty(part, propertyName, isReportProperty, ref doubleValue); doubleValue = doubleValue / 92903.04; result = doubleValue.ToString(doubleFromat); break; case PropertyTypes.Ft3: GetProperty(part, propertyName, isReportProperty, ref doubleValue); doubleValue = doubleValue / 28316846.6; result = doubleValue.ToString(doubleFromat); break; case PropertyTypes.Yard: GetProperty(part, propertyName, isReportProperty, ref doubleValue); doubleValue = doubleValue / 914.4; result = doubleValue.ToString(doubleFromat); break; case PropertyTypes.Yard2: GetProperty(part, propertyName, isReportProperty, ref doubleValue); doubleValue = doubleValue / 836127.36; result = doubleValue.ToString(doubleFromat); break; case PropertyTypes.Yard3: GetProperty(part, propertyName, isReportProperty, ref doubleValue); doubleValue = doubleValue / 764554857.984; result = doubleValue.ToString(doubleFromat); break; case PropertyTypes.Lbs: GetProperty(part, propertyName, isReportProperty, ref doubleValue); doubleValue = doubleValue / 0.45359237; result = doubleValue.ToString(doubleFromat); break; case PropertyTypes.TonShort: GetProperty(part, propertyName, isReportProperty, ref doubleValue); doubleValue = doubleValue / 907.18474; result = doubleValue.ToString(doubleFromat); break; case PropertyTypes.TonLong: GetProperty(part, propertyName, isReportProperty, ref doubleValue); doubleValue = doubleValue / 1016.0469088; result = doubleValue.ToString(doubleFromat); break; } return(result ?? string.Empty); }
private static bool GetAttributeByUDAFormula( PresentedPropertiesXml presentedPropertiesInstance, ModelObject modelObj, string udaEquation, out double resultValue) { var removeChar = new[] { '+', '-', '*', '/', '(', ')' }; const string DelimStr = " "; var delimiter = DelimStr.ToCharArray(); string insertAddstr; var findIndex = 0; double doubleValue; var culInfo = CultureInfo.CurrentCulture; var usCulInfo = new CultureInfo("en-us"); resultValue = 0.0; var findString = udaEquation; for (var i = 0; i < removeChar.Length; i++) { findString = findString.Replace(removeChar[i].ToString(CultureInfo.InvariantCulture), " "); } var splitKey = findString.Split(delimiter); var tempKey = new string[splitKey.Length]; for (var i = 0; i < splitKey.Length; i++) { if (splitKey[i].Length <= 0) { continue; } var isDouble = double.TryParse(splitKey[i], NumberStyles.Any, culInfo, out doubleValue); if (isDouble == false) { isDouble = double.TryParse(splitKey[i], NumberStyles.Any, usCulInfo, out doubleValue); } if (isDouble == false) { tempKey[i] = splitKey[i]; insertAddstr = "_UDA_" + i.ToString(CultureInfo.InvariantCulture); findIndex = udaEquation.IndexOf(splitKey[i], findIndex, StringComparison.Ordinal); findIndex = findIndex + splitKey[i].Length; udaEquation = udaEquation.Insert(findIndex, insertAddstr); } } for (var i = 0; i < tempKey.Length; i++) { if (null == tempKey[i] || tempKey[i].Length == 0) { continue; } PresentedProperties property = null; if (!presentedPropertiesInstance.GetPropertyByNameOrModelPropertyName(tempKey[i], ref property)) { continue; } // Maybe should use just visible property name? var propertvalueY = GetPropertvalueYBasedOnType( presentedPropertiesInstance, modelObj, property, true, false); try { doubleValue = Convert.ToDouble(propertvalueY); insertAddstr = tempKey[i] + "_UDA_" + i.ToString(CultureInfo.InvariantCulture); udaEquation = udaEquation.Replace(insertAddstr, doubleValue.ToString(CultureInfo.InvariantCulture)); } catch (Exception ee) { Debug.WriteLine(ee); return(false); } } var mathEval = new MathEvaluate(); if (mathEval.Parse(udaEquation) && mathEval.Error == false) { mathEval.Infix2Postfix(); mathEval.EvaluatePostfix(); } if (mathEval.Error) { if (mathEval.ErrorDescription != MathEvaluate.DivideByZero) { return(false); } } else { resultValue = mathEval.Result; } return(true); }