//
// (C) Copyright 2003-2008 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using System.ComponentModel;
using System.Text;
using Autodesk.Revit;
using Autodesk.Revit.Elements;
using Autodesk.Revit.Parameters;
using Autodesk.Revit.Symbols;
using Autodesk.Revit.Site;
namespace Revit.SDK.Samples.ProjectInfo.CS
{
///
/// wrapper interface
///
public interface IWrapper
{
#region Properties
///
/// Gets the handle object.
///
object Handle
{
get;
}
///
/// Gets the name of the handle.
///
string Name
{
get;
}
#endregion
}
///
/// Wrapper class for ProjectInfo
///
public class ProjectInfoWrapper : IWrapper
{
#region Fields
///
/// ProjectInfo
///
private Autodesk.Revit.Elements.ProjectInfo m_projectInfo;
#endregion
#region Constructors
///
/// Initializes private variables.
///
/// ProjectInfo
public ProjectInfoWrapper(Autodesk.Revit.Elements.ProjectInfo projectInfo)
{
m_projectInfo = projectInfo;
}
#endregion
#region Properties
///
/// Gets gbXMLSettings
///
[Category("Energy Analysis"), DisplayName("Energy Data"), TypeConverter(typeof(WrapperConverter)),
RevitVersion(RevitStartInfo.RME, RevitStartInfo.RAC)]
public ICustomTypeDescriptor gbXMLSettings
{
get
{
return new WrapperCustomDescriptor(new gbXMLParamElemWrapper(m_projectInfo.gbXMLSettings));
}
}
///
/// Gets or sets Project Issue Data
///
[Category("Other"), DisplayName("Project Issue Data")]
public String IssueDate
{
get
{
return m_projectInfo.IssueDate;
}
set
{
m_projectInfo.IssueDate = value;
}
}
///
/// Gets or sets Project Status
///
[Category("Other"), DisplayName("Project Status")]
public String Status
{
get
{
return m_projectInfo.Status;
}
set
{
m_projectInfo.Status = value;
}
}
///
/// Gets or sets Client Name
///
[Category("Other"), DisplayName("Client Name")]
public String ClientName
{
get
{
return m_projectInfo.ClientName;
}
set
{
m_projectInfo.ClientName = value;
}
}
///
/// Gets or sets Project Address
///
[Category("Other"), DisplayName("Project Address")]
public String Address
{
get
{
return m_projectInfo.Address;
}
set
{
m_projectInfo.Address = value;
}
}
///
/// Gets or sets Project Number
///
[Category("Other"), DisplayName("Project Number")]
public String Number
{
get
{
return m_projectInfo.Number;
}
set
{
m_projectInfo.Number = value;
}
}
#region IWrapper Members
///
/// Gets the handle object.
///
[Browsable(false)]
public object Handle
{
get
{
return m_projectInfo;
}
}
///
/// Gets the name of the handle.
///
[Category("Other"), DisplayName("Project Name")]
public String Name
{
get
{
return m_projectInfo.Name;
}
set
{
m_projectInfo.Name = value;
}
}
#endregion
#endregion
}
///
/// Wrapper class for gbXMLParamElem
///
public class gbXMLParamElemWrapper : IWrapper
{
#region Fields
///
/// gbXMLParamElem
///
private gbXMLParamElem m_gbXMLParamElem;
///
/// SliverSpaceTolerance Parameter
///
private Parameter m_sliverSpaceToleranceParameter;
#endregion
#region Constructors
///
/// Initializes private variables.
///
/// gbXMLParamElem
public gbXMLParamElemWrapper(gbXMLParamElem gbXMLParamElem)
{
m_gbXMLParamElem = gbXMLParamElem;
m_sliverSpaceToleranceParameter = m_gbXMLParamElem.get_Parameter(BuiltInParameter.RBS_ENERGY_ANALYSIS_SLIVER_SPACE_TOLERANCE);
}
#endregion
#region Properties
///
/// Gets or sets Project Phase
///
[DisplayName("Project Phase"), TypeConverter(typeof(ElementConverter))]
public Phase ProjectPhase
{
get
{
return m_gbXMLParamElem.ProjectPhase;
}
set
{
m_gbXMLParamElem.ProjectPhase = value;
}
}
///
/// Gets or sets Shading Surfaces
///
[DisplayName("Shading Surfaces"), RevitVersion(RevitStartInfo.RME, RevitStartInfo.RAC)]
public Boolean ShadingSurfaces
{
get
{
return m_gbXMLParamElem.ShadingSurfaces;
}
set
{
m_gbXMLParamElem.ShadingSurfaces = value;
}
}
///
/// Gets or sets Ground Plane
///
[DisplayName("Ground Plane"), TypeConverter(typeof(ElementConverter)), RevitVersion(RevitStartInfo.RME, RevitStartInfo.RAC)]
public Level GroundPlane
{
get
{
return m_gbXMLParamElem.GroundPlane;
}
set
{
m_gbXMLParamElem.GroundPlane = value;
}
}
///
/// Gets Building Construction
///
[DisplayName("Building Construction"), TypeConverter(typeof(WrapperConverter)), RevitVersion(RevitStartInfo.RME)]
public MEPBuildingConstructionWrapper BuildingConstruction
{
get
{
return new MEPBuildingConstructionWrapper(m_gbXMLParamElem.BuildingConstruction);
}
}
///
/// Gets or sets Building Service
///
[DisplayName("Building Service"), TypeConverter(typeof(ServiceTypeConverter)), RevitVersion(RevitStartInfo.RME)]
public ServiceType BuildingService
{
get
{
return m_gbXMLParamElem.BuildingService;
}
set
{
m_gbXMLParamElem.BuildingService = value;
}
}
///
/// Gets Location
///
[DisplayName("Location"), TypeConverter(typeof(WrapperConverter)), RevitVersion(RevitStartInfo.RME)]
public ProjectLocationWrapper ProjectLocation
{
get
{
return new ProjectLocationWrapper(m_gbXMLParamElem.ProjectLocation);
}
}
///
/// Gets or sets Postal Code
///
[DisplayName("Postal Code")]
public String PostalCode
{
get
{
return m_gbXMLParamElem.PostalCode;
}
set
{
m_gbXMLParamElem.PostalCode = value;
}
}
///
/// Gets or sets Building Type
///
[DisplayName("Building Type"), TypeConverter(typeof(BuildingTypeConverter))]
public BuildingType BuildingType
{
get
{
return m_gbXMLParamElem.BuildingType;
}
set
{
m_gbXMLParamElem.BuildingType = value;
}
}
///
/// Gets or sets Sliver Space Tolerance
///
[DisplayName("Sliver Space Tolerance")]
public String SliverSpaceTolerance
{
get
{
return m_sliverSpaceToleranceParameter.AsValueString();
}
set
{
if(!m_sliverSpaceToleranceParameter.SetValueString(value))
{
throw new ArgumentOutOfRangeException("value");
}
}
}
#region IWrapper Members
///
/// Gets the handle object.
///
[Browsable(false)]
public object Handle
{
get
{
return m_gbXMLParamElem;
}
}
///
/// Gets the name of the handle.
///
[Browsable(false)]
public string Name
{
get
{
return m_gbXMLParamElem.Name;
}
set
{
m_gbXMLParamElem.Name = value;
}
}
#endregion
#endregion
}
///
/// Wrapper class for MEPBuildingConstruction
///
public class MEPBuildingConstructionWrapper : IWrapper
{
#region Fields
///
/// MEPBuildingConstruction
///
private MEPBuildingConstruction m_mEPBuildingConstruction;
#endregion
#region Constructors
///
/// Initializes private variables.
///
/// MEPBuildingConstruction
public MEPBuildingConstructionWrapper(MEPBuildingConstruction mEPBuildingConstruction)
{
m_mEPBuildingConstruction = mEPBuildingConstruction;
}
#endregion
#region Properties
///
/// Gets or sets Exterior Walls
///
[DisplayName("Exterior Walls")]
public ConstructionWrapper ExteriorWalls
{
get
{
return new ConstructionWrapper(m_mEPBuildingConstruction.get_BuildingConstruction(ConstructionType.ExteriorWalls));
}
set
{
m_mEPBuildingConstruction.set_BuildingConstruction(ConstructionType.ExteriorWalls, value.Handle as Construction);
}
}
///
/// Gets or sets Interior Walls
///
[DisplayName("Interior Walls")]
public ConstructionWrapper InteriorWalls
{
get
{
return new ConstructionWrapper(m_mEPBuildingConstruction.get_BuildingConstruction(ConstructionType.InteriorWalls));
}
set
{
m_mEPBuildingConstruction.set_BuildingConstruction(ConstructionType.InteriorWalls, value.Handle as Construction);
}
}
///
/// Gets or sets Slabs
///
[DisplayName("Slabs")]
public ConstructionWrapper Slabs
{
get
{
return new ConstructionWrapper(m_mEPBuildingConstruction.get_BuildingConstruction(ConstructionType.Slabs));
}
set
{
m_mEPBuildingConstruction.set_BuildingConstruction(ConstructionType.Slabs, value.Handle as Construction);
}
}
///
/// Gets or sets Roofs
///
[DisplayName("Roofs")]
public ConstructionWrapper Roofs
{
get
{
return new ConstructionWrapper(m_mEPBuildingConstruction.get_BuildingConstruction(ConstructionType.Roofs));
}
set
{
m_mEPBuildingConstruction.set_BuildingConstruction(ConstructionType.Roofs, value.Handle as Construction);
}
}
///
/// Gets or sets Floors
///
[DisplayName("Floors")]
public ConstructionWrapper Floors
{
get
{
return new ConstructionWrapper(m_mEPBuildingConstruction.get_BuildingConstruction(ConstructionType.Floors));
}
set
{
m_mEPBuildingConstruction.set_BuildingConstruction(ConstructionType.Floors, value.Handle as Construction);
}
}
///
/// Gets or sets Doors
///
[DisplayName("Doors")]
public ConstructionWrapper Doors
{
get
{
return new ConstructionWrapper(m_mEPBuildingConstruction.get_BuildingConstruction(ConstructionType.Doors));
}
set
{
m_mEPBuildingConstruction.set_BuildingConstruction(ConstructionType.Doors, value.Handle as Construction);
}
}
///
/// Gets or sets Exterior Windows
///
[DisplayName("Exterior Windows")]
public ConstructionWrapper ExteriorWindows
{
get
{
return new ConstructionWrapper(m_mEPBuildingConstruction.get_BuildingConstruction(ConstructionType.ExteriorWindows));
}
set
{
m_mEPBuildingConstruction.set_BuildingConstruction(ConstructionType.ExteriorWindows, value.Handle as Construction);
}
}
///
/// Gets or sets Interior Windows
///
[DisplayName("Interior Windows")]
public ConstructionWrapper InteriorWindows
{
get
{
return new ConstructionWrapper(m_mEPBuildingConstruction.get_BuildingConstruction(ConstructionType.InteriorWindows));
}
set
{
m_mEPBuildingConstruction.set_BuildingConstruction(ConstructionType.InteriorWindows, value.Handle as Construction);
}
}
///
/// Gets or sets Skylights
///
[DisplayName("Skylights")]
public ConstructionWrapper Skylights
{
get
{
return new ConstructionWrapper(m_mEPBuildingConstruction.get_BuildingConstruction(ConstructionType.Skylights));
}
set
{
m_mEPBuildingConstruction.set_BuildingConstruction(ConstructionType.Skylights, value.Handle as Construction);
}
}
#region IWrapper Members
///
/// Gets the handle object.
///
[Browsable(false)]
public object Handle
{
get
{
return m_mEPBuildingConstruction;
}
}
///
/// Gets the name of the handle.
///
[Browsable(false)]
public string Name
{
get
{
return m_mEPBuildingConstruction.Name;
}
set
{
m_mEPBuildingConstruction.Name = value;
}
}
#endregion
#endregion
#region Methods
///
/// Get constructions
///
/// ConstructionType
/// Related Constructions specified by constructionTypes
public Autodesk.Revit.Collections.Set get_Constructions(ConstructionType constructionType)
{
return m_mEPBuildingConstruction.get_Constructions(constructionType);
}
#endregion
}
///
/// Wrapper class for Construction
///
[TypeConverter(typeof(ConstructionWrapperConverter))]
public class ConstructionWrapper : IComparable, IWrapper
{
#region Fields
///
/// Construction
///
private Construction m_construction;
#endregion
#region Constructors
///
/// Initializes private variables.
///
/// Construction
public ConstructionWrapper(Construction construction)
{
m_construction = construction;
}
#endregion
#region Properties
#region IComparable Members
///
/// Compares the names of Constructions.
///
/// ConstructionWrapper used to compare
/// A 32-bit signed integer that indicates the relative order of the objects
/// being compared. The return value has these meanings:
/// Value Condition Less than zero This instance is less than value.
/// Zero This instance is equal to value. Greater than zero This instance is
/// greater than value.-or- value is null.
public int CompareTo(object obj)
{
ConstructionWrapper wrapper = obj as ConstructionWrapper;
if (wrapper != null)
{
return this.Name.CompareTo(wrapper.Name);
}
return 1;
}
#endregion
#region IWrapper Members
///
/// Gets the handle object.
///
[Browsable(false)]
public object Handle
{
get { return m_construction; }
}
///
/// Gets the name of the handle.
///
[Browsable(false)]
public String Name
{
get
{
return m_construction.Name;
}
}
#endregion
#endregion
}
///
/// Wrapper class for ProjectLocation
///
public class ProjectLocationWrapper : IWrapper
{
#region Fields
///
/// ProjectLocation
///
private ProjectLocation m_projectLocation;
#endregion
#region Constructors
///
/// Initializes private variables.
///
/// ProjectLocation
public ProjectLocationWrapper(ProjectLocation projectLocation)
{
m_projectLocation = projectLocation;
}
#endregion
#region Properties
///
/// Gets Site Location
///
[DisplayName("Site Location"), TypeConverter(typeof(WrapperConverter))]
public SiteLocationWrapper SiteLocation
{
get
{
return new SiteLocationWrapper(m_projectLocation.SiteLocation);
}
}
#region IWrapper Members
///
/// Gets the handle object.
///
[Browsable(false)]
public object Handle
{
get { return m_projectLocation; }
}
///
/// Gets the name of the handle.
///
public String Name
{
get
{
return m_projectLocation.Name;
}
set
{
m_projectLocation.Name = value;
}
}
#endregion
#endregion
}
///
/// Wrapper class for SiteLocation
///
public class SiteLocationWrapper : IWrapper
{
#region Fields
///
/// SiteLocation
///
private SiteLocation m_siteLocation;
#endregion
#region Constructors
///
/// Initializes private variables.
///
///
public SiteLocationWrapper(SiteLocation siteLocation)
{
m_siteLocation = siteLocation;
}
#endregion
#region Properties
///
/// Gets or sets TimeZone
///
[DisplayName("Time Zone"), TypeConverter(typeof(TimeZoneConverter))]
public String TimeZone
{
get
{
return GetTimeZoneFromDouble(m_siteLocation.TimeZone);
}
set
{
m_siteLocation.TimeZone = GetTimeZoneFromString(value);
}
}
///
/// Gets or sets Longitude
///
[DisplayName("Longitude")]
public String Longitude
{
get
{
return Double2AngleString(m_siteLocation.Longitude);
}
set
{
m_siteLocation.Longitude = AngleString2Double(value);
}
}
///
/// Gets or sets Latitude
///
[DisplayName("Latitude")]
public String Latitude
{
get
{
return Double2AngleString(m_siteLocation.Latitude);
}
set
{
m_siteLocation.Latitude = AngleString2Double(value);
}
}
#region IWrapper Members
///
/// Gets the handle object.
///
[Browsable(false)]
public object Handle
{
get { return m_siteLocation; }
}
///
/// Gets the name of the handle.
///
[Browsable(false)]
public String Name
{
get
{
return m_siteLocation.Name;
}
set
{
m_siteLocation.Name = value;
}
}
#endregion
#endregion
#region Methods
///
/// Get time zone double value from time zone string
///
/// time zone string
/// the value of time zone
private double GetTimeZoneFromString(string value)
{
//i.e. convert "(GMT-12:00) International Date Line West" to 12.0
//i.e. convert "(GMT-03:30) Newfoundland" to 3.30
string timeZoneDouble = value.Substring(4, value.IndexOf(')') - 4).Replace(':', '.').Trim();
if (string.IsNullOrEmpty(timeZoneDouble))
return 0d;
else
return Double.Parse(timeZoneDouble);
}
///
/// Get time zone display string from time zone value
///
/// zone value
/// display string
private string GetTimeZoneFromDouble(double timeZone)
{
// i.e. get "(GMT-04:00) Santiago" from double number 4.0
// should find the last one who matches the time zone
string lastTimeZone = null;
foreach (string tmpTimeZone in RevitStartInfo.TimeZones)
{
object tmpZone = this.GetTimeZoneFromString(tmpTimeZone);
if ((double)tmpZone == timeZone)
lastTimeZone = tmpTimeZone;
}
return lastTimeZone;
}
///
/// Convert angle string to double value
///
/// Angle string
/// Double value
private static double AngleString2Double(string value)
{
int n = value.Length - 1;
if (!char.IsDigit(value[n]))
{
value = value.Substring(0, n);
}
return Double.Parse(value) * 0.0174532925199433;
}
///
/// Convert double value to angle string
///
/// Angle value
/// Angle string, the unit is degree.
private string Double2AngleString(Double value)
{
// 0xb0 is ASCII for unit flag of "degree"
return ((object)Math.Round(value / 0.0174532925199433, 3)).ToString() + (char)0xb0;
}
#endregion
}
}