private static IfcPropertyTemplate ExportIfcPropertyTemplate(DocProperty docProp, IfcLibraryInformation ifcLibInfo, Dictionary<string, DocPropertyEnumeration> mapEnums)
{
if (docProp.PropertyType == DocPropertyTemplateTypeEnum.COMPLEX)
{
IfcComplexPropertyTemplate ifcProp = new IfcComplexPropertyTemplate();
ifcProp.GlobalId = SGuid.Format(docProp.Uuid);
ifcProp.Name = docProp.Name;
ifcProp.Description = docProp.Documentation;
ifcProp.TemplateType = IfcComplexPropertyTemplateTypeEnum.P_COMPLEX;
ifcProp.UsageName = docProp.PrimaryDataType;
foreach (DocProperty docSubProp in docProp.Elements)
{
IfcPropertyTemplate ifcSub = ExportIfcPropertyTemplate(docSubProp, ifcLibInfo, mapEnums);
ifcProp.HasPropertyTemplates.Add(ifcSub);
}
return ifcProp;
}
else
{
IfcSimplePropertyTemplate ifcProp = new IfcSimplePropertyTemplate();
ifcProp.GlobalId = SGuid.Format(docProp.Uuid);
ifcProp.Name = docProp.Name;
ifcProp.Description = docProp.Documentation;
ifcProp.TemplateType = (IfcSimplePropertyTemplateTypeEnum)Enum.Parse(typeof(IfcSimplePropertyTemplateTypeEnum), docProp.PropertyType.ToString());
ifcProp.PrimaryMeasureType = docProp.PrimaryDataType;
ifcProp.SecondaryMeasureType = docProp.SecondaryDataType;
foreach (DocLocalization docLoc in docProp.Localization)
{
IfcLibraryReference ifcLib = new IfcLibraryReference();
ifcLib.Language = docLoc.Locale;
ifcLib.Name = docLoc.Name;
ifcLib.Description = docLoc.Documentation;
ifcLib.ReferencedLibrary = ifcLibInfo;
IfcRelAssociatesLibrary ifcRal = new IfcRelAssociatesLibrary();
ifcRal.RelatingLibrary = ifcLib;
ifcRal.RelatedObjects.Add(ifcProp);
ifcProp.HasAssociations.Add(ifcRal);
}
// enumerations
if (ifcProp.TemplateType == IfcSimplePropertyTemplateTypeEnum.P_ENUMERATEDVALUE && ifcProp.SecondaryMeasureType != null)
{
// NEW: lookup formal enumeration
string propdatatype = ifcProp.SecondaryMeasureType;
int colon = propdatatype.IndexOf(':');
if(colon > 0)
{
propdatatype = propdatatype.Substring(0, colon);
}
DocPropertyEnumeration docEnumeration = null;
if(mapEnums.TryGetValue(propdatatype, out docEnumeration))
{
ifcProp.Enumerators = new IfcPropertyEnumeration();
ifcProp.GlobalId = SGuid.Format(docEnumeration.Uuid);
ifcProp.Enumerators.Name = docEnumeration.Name;
ifcProp.Enumerators.EnumerationValues = new List<IfcValue>();
ifcProp.SecondaryMeasureType = null;
foreach(DocPropertyConstant docConst in docEnumeration.Constants)
{
IfcLabel label = new IfcLabel();
label.Value = docConst.Name;
ifcProp.Enumerators.EnumerationValues.Add(label);
foreach (DocLocalization docLoc in docConst.Localization)
{
IfcLibraryReference ifcLib = new IfcLibraryReference();
ifcLib.Identification = docConst.Name; // distinguishes the constant value within the enumeration
ifcLib.Language = docLoc.Locale;
ifcLib.Name = docLoc.Name;
ifcLib.Description = docLoc.Documentation;
ifcLib.ReferencedLibrary = ifcLibInfo;
if(docLoc.Documentation == null && docLoc.Locale == "en")
{
ifcLib.Description = docConst.Documentation;
}
IfcRelAssociatesLibrary ifcRal = new IfcRelAssociatesLibrary();
ifcRal.RelatingLibrary = ifcLib;
ifcRal.RelatedObjects.Add(ifcProp);
ifcProp.HasAssociations.Add(ifcRal);
}
}
}
}
return ifcProp;
}
}