public void DoBinding(MaterialInfo materialParams, MaterialLayerDescription layerDescription, Autodesk.Revit.DB.DisplayUnit?unitSystem) { if (layerDescription != null) { string unitThicknessName = "LayerThickness"; string unitOffsetName = "LayerOffset"; string unitThickness; string unitOffset; if (null == unitSystem) { unitThickness = UnitsAssignment.GetUnitSymbol(unitThicknessName, ElementInfoUnits.Assignments); unitOffset = UnitsAssignment.GetUnitSymbol(unitOffsetName, ElementInfoUnits.Assignments); } else { unitThickness = UnitsAssignment.GetUnitSymbol(unitThicknessName, ElementInfoUnits.Assignments, (Autodesk.Revit.DB.DisplayUnit)unitSystem); unitOffset = UnitsAssignment.GetUnitSymbol(unitOffsetName, ElementInfoUnits.Assignments, (Autodesk.Revit.DB.DisplayUnit)unitSystem); } string stringThicknessValue = layerDescription.LayerThickness.ToString(); string stringOffsetValue = layerDescription.LayerOffset.ToString(); if (null == unitSystem) { stringThicknessValue = UnitsAssignment.FormatToRevitUI(unitThicknessName, layerDescription.LayerThickness, ElementInfoUnits.Assignments); stringOffsetValue = UnitsAssignment.FormatToRevitUI(unitOffsetName, layerDescription.LayerOffset, ElementInfoUnits.Assignments); } LayerThickness.Content = stringThicknessValue + " " + unitThickness; LayerOffset.Content = stringOffsetValue + " " + unitOffset; LayerDescription.Visibility = System.Windows.Visibility.Visible; } else { LayerDescription.Visibility = System.Windows.Visibility.Collapsed; } List <MaterialParameterDescription> matParDescrList = new List <MaterialParameterDescription>(); if (materialParams.Category != MaterialCategory.Undefined) { MaterialName.Content = materialParams.Properties.Name; MaterialDescription.Content = materialParams.Properties.Description; MaterialCharacteristics materialCharacteristics = materialParams.Characteristics; foreach (object o in materialCharacteristics) { List <MaterialParameterDescription> matParDescr = ParameterBinding(o, materialCharacteristics, MaterialCharacteristicsUnits.Assignments, unitSystem); if (null == matParDescr) { continue; } matParDescrList.AddRange(matParDescr); } } switch (materialParams.Category) { case MaterialCategory.Concrete: MaterialConcreteCharacteristics concrete = (MaterialConcreteCharacteristics)materialParams.Characteristics.Specific; foreach (object o in concrete) { List <MaterialParameterDescription> matParDescr = ParameterBinding(o, concrete, MaterialConcreteCharacteristicsUnits.Assignments, unitSystem); if (matParDescr != null) { matParDescrList.AddRange(matParDescr); } } break; case MaterialCategory.Metal: MaterialMetalCharacteristics metal = (MaterialMetalCharacteristics)materialParams.Characteristics.Specific; foreach (object o in metal) { List <MaterialParameterDescription> matParDescr = ParameterBinding(o, metal, MaterialMetalCharacteristicsUnits.Assignments, unitSystem); if (matParDescr != null) { matParDescrList.AddRange(matParDescr); } } break; case MaterialCategory.Timber: MaterialTimberCharacteristics timber = (MaterialTimberCharacteristics)materialParams.Characteristics.Specific; foreach (object o in timber) { List <MaterialParameterDescription> matParDescr = ParameterBinding(o, timber, MaterialTimberCharacteristicsUnits.Assignments, unitSystem); if (matParDescr != null) { matParDescrList.AddRange(matParDescr); } } break; } materialParameters.ItemsSource = matParDescrList; }
//-------------------------------------------------------------- #endregion #region public methods //-------------------------------------------------------------- public void DataBinding(Autodesk.Revit.DB.Element revitElement) { UnitsAssignment.RevitUnits = revitElement.Document.GetUnits(); if (null == revitElementAnalyser) { revitElementAnalyser = revitUnitsUI ? new ElementAnalyser() : new ElementAnalyser(unitSystem); revitElementAnalyser.TSectionAnalysis = true; } ElementInfo elementInfo = revitElementAnalyser.Analyse(revitElement); switch (elementInfo.Type) { case ElementType.Beam: case ElementType.Column: elementSizeLabel.Content = "Length:"; if (revitUnitsUI) { elementSizeValue.Content = UnitsAssignment.FormatToRevitUI("GeomLength", elementInfo.GeomLength(), ElementInfoUnits.Assignments, true); } else { elementSizeValue.Content = elementInfo.GeomLength().ToString(); elementSizeValue.Content += " " + UnitsAssignment.GetUnitSymbol("GeomLength", ElementInfoUnits.Assignments, unitSystem); } SectionShapeType shapeType = SectionShapeType.Unusual; if (elementInfo.SectionsParams != null) { shapeType = elementInfo.SectionsParams.ShapeType; } bool tSectionCollapsedWhenSelected = false; tabSlab.Visibility = System.Windows.Visibility.Collapsed; tabWall.Visibility = System.Windows.Visibility.Collapsed; if (elementInfo.Slabs != null && elementInfo.Slabs.TSection != null) { tabTSection.Visibility = System.Windows.Visibility.Visible; tSectionDescription.DoBinding(elementInfo.Slabs, revitUnitsUI ? null : (Autodesk.Revit.DB.DisplayUnit?)unitSystem, elementInfo.GeomLength()); } else { if (tabTSection.IsSelected) { tSectionCollapsedWhenSelected = true; } tabTSection.Visibility = System.Windows.Visibility.Collapsed; } tabProfile.Visibility = System.Windows.Visibility.Visible; if (tabSlab.IsSelected || true == tSectionCollapsedWhenSelected || tabWall.IsSelected) { IInputElement previousFocusedElement = FocusManager.GetFocusedElement(this); tabProfile.Focus(); if (previousFocusedElement != null) { previousFocusedElement.Focus(); } } sectionDescription.DoBinding(shapeType, elementInfo.Sections, elementInfo.Material != null ? elementInfo.Material.Category == MaterialCategory.Metal : false); sectionParameters.DoBinding(revitElement.Name, elementInfo.SectionsParams, revitUnitsUI ? null : (Autodesk.Revit.DB.DisplayUnit?)unitSystem); break; case ElementType.Slab: elementSizeLabel.Content = "Thickness:"; if (revitUnitsUI) { if (elementInfo.Slabs.AsElement != null) { elementSizeValue.Content = UnitsAssignment.FormatToRevitUI("SlabThickness", elementInfo.Slabs.AsElement.Thickness(), ElementInfoUnits.Assignments, true); } } else { if (elementInfo.Slabs.AsElement != null) { elementSizeValue.Content = elementInfo.Slabs.AsElement.Thickness().ToString(); elementSizeValue.Content += " " + UnitsAssignment.GetUnitSymbol("SlabThickness", ElementInfoUnits.Assignments, unitSystem); } } tabProfile.Visibility = System.Windows.Visibility.Collapsed; tabTSection.Visibility = System.Windows.Visibility.Collapsed; tabWall.Visibility = System.Windows.Visibility.Collapsed; tabSlab.Visibility = System.Windows.Visibility.Visible; if (tabProfile.IsSelected || tabTSection.IsSelected || tabWall.IsSelected) { IInputElement previousFocusedElement = FocusManager.GetFocusedElement(this); tabSlab.Focus(); if (previousFocusedElement != null) { previousFocusedElement.Focus(); } } slabDescription.DoBinding(elementInfo.Slabs, revitUnitsUI ? null : (Autodesk.Revit.DB.DisplayUnit?)unitSystem); break; case ElementType.Wall: elementSizeLabel.Content = "Thickness:"; if (revitUnitsUI) { elementSizeValue.Content = UnitsAssignment.FormatToRevitUI("WallThickness", elementInfo.Walls.AsElement.Thickness(), ElementInfoUnits.Assignments, true); } else { elementSizeValue.Content = elementInfo.Walls.AsElement.Thickness().ToString(); elementSizeValue.Content += " " + UnitsAssignment.GetUnitSymbol("SlabThickness", ElementInfoUnits.Assignments, unitSystem); } tabProfile.Visibility = System.Windows.Visibility.Collapsed; tabTSection.Visibility = System.Windows.Visibility.Collapsed; tabSlab.Visibility = System.Windows.Visibility.Collapsed; tabWall.Visibility = System.Windows.Visibility.Visible; if (tabProfile.IsSelected || tabSlab.IsSelected || tabTSection.IsSelected) { IInputElement previousFocusedElement = FocusManager.GetFocusedElement(this); tabWall.Focus(); if (previousFocusedElement != null) { previousFocusedElement.Focus(); } } wallDescription.DoBinding(elementInfo.Walls.AsElement, revitUnitsUI ? null : (Autodesk.Revit.DB.DisplayUnit?)unitSystem); break; case ElementType.Unknown: default: elementSizeLabel.Content = ""; elementSizeValue.Content = ""; tabProfile.Visibility = System.Windows.Visibility.Collapsed; tabSlab.Visibility = System.Windows.Visibility.Collapsed; tabTSection.Visibility = System.Windows.Visibility.Collapsed; tabWall.Visibility = System.Windows.Visibility.Collapsed; if (tabProfile.IsSelected || tabSlab.IsSelected || tabTSection.IsSelected || tabWall.IsSelected) { IInputElement previousFocusedElement = FocusManager.GetFocusedElement(this); tabMaterial.Focus(); if (previousFocusedElement != null) { previousFocusedElement.Focus(); } } break; } MaterialLayerDescription layerDescription = null; Layer structuralLayer = null; if (elementInfo.Type == ElementType.Slab) { if (elementInfo.Slabs.AsElement != null) { structuralLayer = elementInfo.Slabs.AsElement.StructuralLayer(); } } if (elementInfo.Type == ElementType.Wall) { structuralLayer = elementInfo.Walls.AsElement.StructuralLayer(); } if (structuralLayer != null) { layerDescription = new MaterialLayerDescription(structuralLayer.Thickness, structuralLayer.Offset); } materialParameters.DoBinding(elementInfo.Material, layerDescription, revitUnitsUI ? null : (Autodesk.Revit.DB.DisplayUnit?)unitSystem); }