Exemplo n.º 1
0
        /// <summary>
        /// Processes an IFC unit in the property.
        /// </summary>
        /// <param name="ifcSimpleProperty">The simple property.</param>
        /// <param name="simplePropertyHandle">The simple property handle.</param>
        static protected void ProcessIFCSimplePropertyUnit(IFCSimpleProperty ifcSimpleProperty, IFCAnyHandle simplePropertyHandle)
        {
            IFCAnyHandle ifcUnitHandle = IFCImportHandleUtil.GetOptionalInstanceAttribute(simplePropertyHandle, "Unit");
            IFCUnit      ifcUnit       = (ifcUnitHandle != null) ? IFCUnit.ProcessIFCUnit(ifcUnitHandle) : null;

            if (ifcUnit == null)
            {
                if (ifcSimpleProperty.IFCPropertyValues.Count > 0)
                {
                    IFCPropertyValue propertyValue = ifcSimpleProperty.IFCPropertyValues[0];
                    if (propertyValue != null && propertyValue.HasValue() &&
                        (propertyValue.Type == IFCDataPrimitiveType.Integer) || (propertyValue.Type == IFCDataPrimitiveType.Double))
                    {
                        string      unitTypeName;
                        ForgeTypeId specTypeId = IFCDataUtil.GetUnitTypeFromData(propertyValue.Value, new ForgeTypeId(), out unitTypeName);
                        if (!specTypeId.Empty())
                        {
                            ifcUnit = IFCImportFile.TheFile.IFCUnits.GetIFCProjectUnit(specTypeId);
                        }
                        else
                        {
                            Importer.TheLog.LogWarning(simplePropertyHandle.StepId, "Unhandled unit type: " + unitTypeName, true);
                        }
                    }
                }
            }

            ifcSimpleProperty.m_IFCUnit = ifcUnit;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Recursively gets all data from a field and appends it in string format to a StringBuilder.
        /// </summary>
        /// <typeparam name="KeyType">The key type of the field -- used only for maps</typeparam>
        /// <typeparam name="FieldType">The data type of the field for simple types and arrays</typeparam>
        /// <param name="field">The field to query</param>
        /// <param name="entity">The entity to query</param>
        /// <param name="strBuilder">The StringBuilder to append entity data to</param>
        private void GetFieldDataAsString <KeyType, FieldType>(Field field, Entity entity, StringBuilder strBuilder)
        {
            string fieldName = field.FieldName;

            System.Type   fieldType          = field.ValueType;
            ForgeTypeId   fieldUnit          = field.GetSpecTypeId();
            ContainerType fieldContainerType = field.ContainerType;

            Type[]   methodGenericParameters       = null;
            object[] invokeParams                  = null;
            Type[]   methodOverloadSelectionParams = null;
            if (field.ContainerType == ContainerType.Simple)
            {
                methodGenericParameters = new Type[] { field.ValueType }
            }
            ;
            else if (field.ContainerType == ContainerType.Array)
            {
                methodGenericParameters = new Type[] { typeof(IList <int>).GetGenericTypeDefinition().MakeGenericType(new Type[] { field.ValueType }) }
            }
            ;
            else //map
            {
                methodGenericParameters = new Type[] { typeof(IDictionary <int, int>).GetGenericTypeDefinition().MakeGenericType(new Type[] { field.KeyType, field.ValueType }) }
            };

            if (fieldUnit.Empty())
            {
                methodOverloadSelectionParams = new Type[] { typeof(Field) };
                invokeParams = new object[] { field };
            }
            else
            {
                methodOverloadSelectionParams = new Type[] { typeof(Field), typeof(ForgeTypeId) };
                invokeParams = new object[] { field, UnitTypeId.Meters };
            }

            MethodInfo instantiatedGenericGetMethod = entity.GetType().GetMethod("Get", methodOverloadSelectionParams).MakeGenericMethod(methodGenericParameters);

            if (field.ContainerType == ContainerType.Simple)
            {
                FieldType retval = (FieldType)instantiatedGenericGetMethod.Invoke(entity, invokeParams);
                if (fieldType == typeof(Entity))
                {
                    Schema subSchema = Schema.Lookup(field.SubSchemaGUID);
                    strBuilder.AppendLine("Field: " + field.FieldName + ", Type: " + field.ValueType.ToString() + ", Value: " + " {SubEntity} " + ", Unit: " + field.GetSpecTypeId().TypeId + ", ContainerType: " + field.ContainerType.ToString());
                    DumpAllSchemaEntityData <FieldType>(retval, subSchema, strBuilder);
                }
                else
                {
                    string sRetval = retval.ToString();
                    strBuilder.AppendLine("Field: " + field.FieldName + ", Type: " + field.ValueType.ToString() + ", Value: " + retval + ", Unit: " + field.GetSpecTypeId().TypeId + ", ContainerType: " + field.ContainerType.ToString());
                }
            }
            else if (field.ContainerType == ContainerType.Array)
            {
                IList <FieldType> listRetval = (IList <FieldType>)instantiatedGenericGetMethod.Invoke(entity, invokeParams);
                if (fieldType == (typeof(Entity)))
                {
                    strBuilder.AppendLine("Field: " + field.FieldName + ", Type: " + field.ValueType.ToString() + ", Value: " + " {SubEntity} " + ", Unit: " + field.GetSpecTypeId().TypeId + ", ContainerType: " + field.ContainerType.ToString());

                    foreach (FieldType fa in listRetval)
                    {
                        strBuilder.Append("  Array Value: ");
                        DumpAllSchemaEntityData <FieldType>(fa, Schema.Lookup(field.SubSchemaGUID), strBuilder);
                    }
                }
                else
                {
                    strBuilder.AppendLine("Field: " + field.FieldName + ", Type: " + field.ValueType.ToString() + ", Value: " + " {Array} " + ", Unit: " + field.GetSpecTypeId().TypeId + ", ContainerType: " + field.ContainerType.ToString());
                    foreach (FieldType fa in listRetval)
                    {
                        strBuilder.AppendLine("  Array value: " + fa.ToString());
                    }
                }
            }
            else //Map
            {
                strBuilder.AppendLine("Field: " + field.FieldName + ", Type: " + field.ValueType.ToString() + ", Value: " + " {Map} " + ", Unit: " + field.GetSpecTypeId().TypeId + ", ContainerType: " + field.ContainerType.ToString());
                IDictionary <KeyType, FieldType> mapRetval = (IDictionary <KeyType, FieldType>)instantiatedGenericGetMethod.Invoke(entity, invokeParams);
                if (fieldType == (typeof(Entity)))
                {
                    strBuilder.AppendLine("Field: " + field.FieldName + ", Type: " + field.ValueType.ToString() + ", Value: " + " {SubEntity} " + ", Unit: " + field.GetSpecTypeId().TypeId + ", ContainerType: " + field.ContainerType.ToString());
                    foreach (FieldType fa in mapRetval.Values)
                    {
                        strBuilder.Append("  Map Value: ");
                        DumpAllSchemaEntityData <FieldType>(fa, Schema.Lookup(field.SubSchemaGUID), strBuilder);
                    }
                }
                else
                {
                    strBuilder.AppendLine("Field: " + field.FieldName + ", Type: " + field.ValueType.ToString() + ", Value: " + " {Map} " + ", Unit: " + field.GetSpecTypeId().TypeId + ", ContainerType: " + field.ContainerType.ToString());
                    foreach (FieldType fa in mapRetval.Values)
                    {
                        strBuilder.AppendLine("  Map value: " + fa.ToString());
                    }
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="revit">The revit application.</param>
        public STLExportForm(Autodesk.Revit.UI.UIApplication revit)
        {
            InitializeComponent();
            m_Revit = revit;

            // get new data generator
            m_Generator = new DataGenerator(m_Revit.Application, m_Revit.ActiveUIDocument.Document, m_Revit.ActiveUIDocument.Document.ActiveView);

            // scan for categories to populate category list
            m_CategoryList = m_Generator.ScanCategories(true);

            foreach (Category category in m_CategoryList.Values)
            {
                TreeNode treeNode = GetChildNode(category, m_Revit.ActiveUIDocument.Document.ActiveView);
                if (treeNode != null)
                {
                    tvCategories.Nodes.Add(treeNode);
                }
            }

            string unitName = "Use Internal: Feet";

            m_DisplayUnits.Add(unitName, new ForgeTypeId());
            int selectedIndex = comboBox_DUT.Items.Add(unitName);

            if (m_SelectedDUT.Empty())
            {
                comboBox_DUT.SelectedIndex = selectedIndex;
            }

            Units       currentUnits = m_Revit.ActiveUIDocument.Document.GetUnits();
            ForgeTypeId currentDut   = currentUnits.GetFormatOptions(SpecTypeId.Length).GetUnitTypeId();

            unitName = "Use Current: " + LabelUtils.GetLabelForUnit(currentDut);
            m_DisplayUnits.Add(unitName, currentDut);
            selectedIndex = comboBox_DUT.Items.Add(unitName);
            if (m_SelectedDUT == currentDut)
            {
                comboBox_DUT.SelectedIndex = selectedIndex;
            }

            foreach (ForgeTypeId dut in UnitUtils.GetValidUnits(SpecTypeId.Length))
            {
                if (currentDut == dut)
                {
                    continue;
                }
                unitName = LabelUtils.GetLabelForUnit(dut);
                m_DisplayUnits.Add(unitName, dut);
                selectedIndex = comboBox_DUT.Items.Add(unitName);
                if (m_SelectedDUT == dut)
                {
                    comboBox_DUT.SelectedIndex = selectedIndex;
                }
            }

            // initialize the UI differently for Families
            if (revit.ActiveUIDocument.Document.IsFamilyDocument)
            {
                cbIncludeLinked.Enabled = false;
                tvCategories.Enabled    = false;
                btnCheckAll.Enabled     = false;
                btnCheckNone.Enabled    = false;
            }
        }