xBIM之二:构建墙和门窗
研究了两天,终于实现了利用xBIM自动输出墙和门窗
比较粗糙的源码如下:
private void Form1_Load(object sender, EventArgs e)
{
//first create and initialise a model called Hello Wall
Console.WriteLine("Initialising the IFC Project....");
using (var model = CreateandInitModel("HelloWall"))
{
if (model != null)
{
IfcBuilding building = CreateBuilding(model, "Default Building");
IfcWallStandardCase wall = CreateWall(model, , , );
IfcDoor door = CreateDoor(model, wall, , , );
IfcWindow widnow = CreateWindow(model, wall, , , );
if (wall != null) AddPropertiesToWall(model, wall);
using (var txn = model.BeginTransaction("Add Wall"))
{
building.AddElement(wall);
building.AddElement(door);
building.AddElement(widnow);
txn.Commit();
} if (wall != null)
{
try
{
Console.WriteLine("Standard Wall successfully created....");
//保存到文件
model.SaveAs("HelloWallIfc4.ifc", IfcStorageType.Ifc);
Console.WriteLine("HelloWallIfc4.ifc has been successfully written");
}
catch (Exception ex)
{
Console.WriteLine("Failed to save HelloWall.ifc");
Console.WriteLine(ex.Message);
}
}
}
else
{
Console.WriteLine("Failed to initialise the model");
}
}
Console.WriteLine("Press any key to exit to view the IFC file....");
Console.ReadKey();
// LaunchNotepad("HelloWallIfc4.ifc");
}
// private static void LaunchNotepad(string fileName)
//{
// Process p;
// try
// { // p = new Process {StartInfo = {FileName = fileName, CreateNoWindow = false}};
// p.Start();
// }
// catch (Exception ex)
// {
// Console.WriteLine("Exception Occurred :{0},{1}",
// ex.Message, ex.StackTrace);
// }
//} private static IfcBuilding CreateBuilding(IfcStore model, string name)
{
//启动事务
using (var txn = model.BeginTransaction("Create Building"))
{
var building = model.Instances.New<IfcBuilding>();
building.Name = name; building.CompositionType = IfcElementCompositionEnum.ELEMENT;
var localPlacement = model.Instances.New<IfcLocalPlacement>();
building.ObjectPlacement = localPlacement;
var placement = model.Instances.New<IfcAxis2Placement3D>();
localPlacement.RelativePlacement = placement;
placement.Location = model.Instances.New<IfcCartesianPoint>(p=>p.SetXYZ(,,));
//获取项目
var project = model.Instances.OfType<IfcProject>().FirstOrDefault();
project.AddBuilding(building);
txn.Commit();
return building;
}
} /// <summary>
/// 设置模型的基本参数、单元、所有权等
/// </summary>
/// <param name="projectName">项目名称</param>
/// <returns></returns>
private static IfcStore CreateandInitModel(string projectName)
{
//首先我们需要为模型创建凭证、这个在之前的文章都有解释
var credentials = new XbimEditorCredentials
{
ApplicationDevelopersName = "xBimTeam",
ApplicationFullName = "Hello Wall Application",
ApplicationIdentifier = "HelloWall.exe",
ApplicationVersion = "1.0",
EditorsFamilyName = "Team",
EditorsGivenName = "xBIM",
EditorsOrganisationName = "xBimTeam"
};
//那么先创建 IfcStore,IfcStore 是IFC4 格式存放在内存中而不是数据库
//如果模型大于50MB的Ifc或者需要强大的事务处理,数据库在性能方面通常会更好 var model = IfcStore.Create(credentials, IfcSchemaVersion.Ifc4,XbimStoreType.InMemoryModel);
// 启动事务、将所有的模型更改为 ACID
using (var txn = model.BeginTransaction("Initialise Model"))
{ //常见项目信息
var project = model.Instances.New<IfcProject>();
//设置单位 这里是英制
project.Initialize(ProjectUnits.SIUnitsUK);
project.Name = projectName; //提交修改
txn.Commit();
}
return model; } /// <summary>
/// 创建墙
/// </summary>
/// <param name="model"></param>
/// <param name="length">矩形的长度 </param>
/// <param name="width">矩形占地面积的宽度(墙的宽度)</param>
/// <param name="height">墙高度</param>
/// <returns></returns>
static private IfcWallStandardCase CreateWall(IfcStore model, double length, double width, double height)
{ //启动事务
using (var txn = model.BeginTransaction("Create Wall"))
{
var wall = model.Instances.New<IfcWallStandardCase>();
wall.Name = "A Standard rectangular wall"; // 墙的矩形剖面
//var rectProf = model.Instances.New<IfcRectangleProfileDef>();
//rectProf.ProfileType = IfcProfileTypeEnum.AREA;
//rectProf.XDim = width;
//rectProf.YDim = length; //var insertPoint = model.Instances.New<IfcCartesianPoint>();
//insertPoint.SetXY(0, 400); //在任意位置插入
//rectProf.Position = model.Instances.New<IfcAxis2Placement2D>();
//rectProf.Position.Location = insertPoint; //var curve=model.Instances.New<IfcCurve>();
IfcPolyline curve = model.Instances.New<IfcPolyline>();
var pt0 = model.Instances.New<IfcCartesianPoint>();
pt0.SetXY(, ); //在任意位置插入
var pt1 = model.Instances.New<IfcCartesianPoint>();
pt1.SetXY(, length / ); //在任意位置插入
var pt2 = model.Instances.New<IfcCartesianPoint>();
pt2.SetXY(, length); //在任意位置插入
curve.Points.Add(pt0);
curve.Points.Add(pt1);
curve.Points.Add(pt2); var rectProf = model.Instances.New<IfcCenterLineProfileDef>();
rectProf.ProfileType = IfcProfileTypeEnum.AREA;
rectProf.Thickness = width;
rectProf.Curve = curve; //模型区域实心
var body = model.Instances.New<IfcExtrudedAreaSolid>();
body.Depth = height;
body.SweptArea = rectProf;
body.ExtrudedDirection = model.Instances.New<IfcDirection>();
body.ExtrudedDirection.SetXYZ(, , ); //在模型中插入几何参数
var origin = model.Instances.New<IfcCartesianPoint>();
origin.SetXYZ(, , );
body.Position = model.Instances.New<IfcAxis2Placement3D>();
body.Position.Location = origin; //创建一个定义形状来保存几何
var shape = model.Instances.New<IfcShapeRepresentation>();
var modelContext = model.Instances.OfType<IfcGeometricRepresentationContext>().FirstOrDefault();
shape.ContextOfItems = modelContext;
shape.RepresentationType = "SweptSolid";
shape.RepresentationIdentifier = "Body";
shape.Items.Add(body); //创建产品定义并将模型几何添加到墙上
var rep = model.Instances.New<IfcProductDefinitionShape>();
rep.Representations.Add(shape);
wall.Representation = rep; //把墙放到模型中
var lp = model.Instances.New<IfcLocalPlacement>();
var ax3D = model.Instances.New<IfcAxis2Placement3D>();
ax3D.Location = origin;
ax3D.RefDirection = model.Instances.New<IfcDirection>();
ax3D.RefDirection.SetXYZ(, , );
ax3D.Axis = model.Instances.New<IfcDirection>();
ax3D.Axis.SetXYZ(, , );
lp.RelativePlacement = ax3D;
wall.ObjectPlacement = lp; //Where子句:IfcWallStandard依赖于提供一个IfcMaterialLayerSetUsage
var ifcMaterialLayerSetUsage = model.Instances.New<IfcMaterialLayerSetUsage>();
var ifcMaterialLayerSet = model.Instances.New<IfcMaterialLayerSet>();
var ifcMaterialLayer = model.Instances.New<IfcMaterialLayer>();
ifcMaterialLayer.LayerThickness = ;
ifcMaterialLayerSet.MaterialLayers.Add(ifcMaterialLayer);
ifcMaterialLayerSetUsage.ForLayerSet = ifcMaterialLayerSet;
ifcMaterialLayerSetUsage.LayerSetDirection = IfcLayerSetDirectionEnum.AXIS2;
ifcMaterialLayerSetUsage.DirectionSense = IfcDirectionSenseEnum.NEGATIVE;
ifcMaterialLayerSetUsage.OffsetFromReferenceLine = ; //添加材料到墙上
var material = model.Instances.New<IfcMaterial>();
material.Name = "some material";
var ifcRelAssociatesMaterial = model.Instances.New<IfcRelAssociatesMaterial>();
ifcRelAssociatesMaterial.RelatingMaterial = material;
ifcRelAssociatesMaterial.RelatedObjects.Add(wall); ifcRelAssociatesMaterial.RelatingMaterial = ifcMaterialLayerSetUsage; //IfcPresentationLayerAssignment对于IfcWall或IfcWallStandardCase中的CAD演示是必需的
var ifcPresentationLayerAssignment = model.Instances.New<IfcPresentationLayerAssignment>();
ifcPresentationLayerAssignment.Name = "some ifcPresentationLayerAssignment";
ifcPresentationLayerAssignment.AssignedItems.Add(shape);
// 如果IfcPolyline具有两个点,则对于IfcWall是必需的
var ifcPolyline = model.Instances.New<IfcPolyline>();
var startPoint = model.Instances.New<IfcCartesianPoint>();
startPoint.SetXY(, );
var endPoint = model.Instances.New<IfcCartesianPoint>();
endPoint.SetXY(, );
ifcPolyline.Points.Add(startPoint);
ifcPolyline.Points.Add(endPoint); var shape2D = model.Instances.New<IfcShapeRepresentation>();
shape2D.ContextOfItems = modelContext;
shape2D.RepresentationIdentifier = "Axis";
shape2D.RepresentationType = "Curve2D";
shape2D.Items.Add(ifcPolyline);
rep.Representations.Add(shape2D); //var rectDoor = model.Instances.New<IfcRectangleProfileDef>();
//rectDoor.ProfileType = IfcProfileTypeEnum.AREA;
//rectDoor.XDim = width;
//rectDoor.YDim = length; //var insertPoint = model.Instances.New<IfcCartesianPoint>();
//insertPoint.SetXY(0, 400); //在任意位置插入
//rectDoor.Position = model.Instances.New<IfcAxis2Placement2D>();
//rectDoor.Position.Location = insertPoint;
////模型区域实心
//var body_door = model.Instances.New<IfcExtrudedAreaSolid>();
//body_door.Depth = height;
//body_door.SweptArea = rectDoor;
//body_door.ExtrudedDirection = model.Instances.New<IfcDirection>();
//body_door.ExtrudedDirection.SetXYZ(0, 0, 1); ////在模型中插入几何参数
//body_door.Position = model.Instances.New<IfcAxis2Placement3D>();
//body_door.Position.Location = origin; ////创建一个定义形状来保存几何
//var shape_door = model.Instances.New<IfcShapeRepresentation>();
//var modelContext_door = model.Instances.OfType<IfcGeometricRepresentationContext>().FirstOrDefault();
//shape_door.ContextOfItems = modelContext_door;
//shape_door.RepresentationType = "SweptSolid";
//shape_door.RepresentationIdentifier = "Body";
//shape_door.Items.Add(body_door); ////创建产品定义并将模型几何添加到墙上
//var rep_door = model.Instances.New<IfcProductDefinitionShape>();
//rep_door.Representations.Add(shape_door); //var door = model.Instances.New<IfcDoor>();
//door.Name = "A Door";
//var lp_door = model.Instances.New<IfcLocalPlacement>();
//var ax3D_door = model.Instances.New<IfcAxis2Placement3D>();
//ax3D_door.Location = origin;
//ax3D_door.RefDirection = model.Instances.New<IfcDirection>();
//ax3D_door.RefDirection.SetXYZ(0, 1, 0);
//ax3D_door.Axis = model.Instances.New<IfcDirection>();
//ax3D_door.Axis.SetXYZ(0, 0, 1);
//lp_door.RelativePlacement = ax3D_door;
//door.ObjectPlacement = lp_door;
//door.Representation = rep_door;
//var m_OpeningEle = model.Instances.New<IfcOpeningElement>();
//m_OpeningEle.Name = "Openings"; //var m_RelFills = model.Instances.New<IfcRelFillsElement>();
//m_RelFills.RelatingOpeningElement = m_OpeningEle;
//m_RelFills.RelatedBuildingElement = door;
//var voidRel = model.Instances.New<IfcRelVoidsElement>();
//voidRel.RelatedOpeningElement = m_OpeningEle;
//voidRel.RelatingBuildingElement = wall; txn.Commit();
return wall;
} }
static private IfcDoor CreateDoor(IfcStore model, IfcWallStandardCase wall, double length, double width, double height)
{
//启动事务
using (var txn = model.BeginTransaction("Create Door"))
{
var rectDoor = model.Instances.New<IfcRectangleProfileDef>();
rectDoor.ProfileType = IfcProfileTypeEnum.AREA;
rectDoor.XDim = width-;
rectDoor.YDim = length; var insertPoint = model.Instances.New<IfcCartesianPoint>();
insertPoint.SetXY(, ); //在任意位置插入
rectDoor.Position = model.Instances.New<IfcAxis2Placement2D>();
rectDoor.Position.Location = insertPoint; //模型区域实心
var body_door = model.Instances.New<IfcExtrudedAreaSolid>();
body_door.Depth = height;
body_door.SweptArea = rectDoor;
body_door.ExtrudedDirection = model.Instances.New<IfcDirection>();
body_door.ExtrudedDirection.SetXYZ(, , ); var origin = model.Instances.New<IfcCartesianPoint>();
origin.SetXYZ(, , );
//在模型中插入几何参数
body_door.Position = model.Instances.New<IfcAxis2Placement3D>();
body_door.Position.Location = origin; //创建一个定义形状来保存几何
var shape_door = model.Instances.New<IfcShapeRepresentation>();
var modelContext_door = model.Instances.OfType<IfcGeometricRepresentationContext>().FirstOrDefault();
shape_door.ContextOfItems = modelContext_door;
shape_door.RepresentationType = "SweptSolid";
shape_door.RepresentationIdentifier = "Body";
shape_door.Items.Add(body_door); //创建产品定义并将模型几何添加到墙上
var rep_door = model.Instances.New<IfcProductDefinitionShape>();
rep_door.Representations.Add(shape_door); var door = model.Instances.New<IfcDoor>();
door.Name = "A Door";
door.PredefinedType = IfcDoorTypeEnum.GATE;
door.OperationType = IfcDoorTypeOperationEnum.DOUBLE_SWING_LEFT;
door.OverallHeight = ;
door.OverallWidth = ; var lp_door = model.Instances.New<IfcLocalPlacement>();
var wallplace = wall.ObjectPlacement;
var ax3D_door = model.Instances.New<IfcAxis2Placement3D>();
var origin2 = model.Instances.New<IfcCartesianPoint>();
origin2.SetXYZ(, , ); ax3D_door.RefDirection = model.Instances.New<IfcDirection>();
ax3D_door.RefDirection.SetXYZ(,, );//x轴
ax3D_door.Axis = model.Instances.New<IfcDirection>();
ax3D_door.Axis.SetXYZ(, , );//Z轴
ax3D_door.Location = origin2;
//lp_door.RelativePlacement = wallplace.RelativePlacement;
lp_door.RelativePlacement = ax3D_door;
lp_door.PlacementRelTo =wallplace;
door.ObjectPlacement = lp_door;
door.Representation = rep_door; ////////////////////////////////////////////////////////////////////
var m_OpeningEle = model.Instances.New<IfcOpeningElement>();
m_OpeningEle.Name = "My Openings";
m_OpeningEle.PredefinedType = IfcOpeningElementTypeEnum.OPENING; var rectOpening = model.Instances.New<IfcRectangleProfileDef>();
rectOpening.ProfileType = IfcProfileTypeEnum.AREA;
rectOpening.XDim = width;
rectOpening.YDim = length;
rectOpening.Position = model.Instances.New<IfcAxis2Placement2D>();
rectOpening.Position.Location = insertPoint; //模型区域实心
var body_Opeinging = model.Instances.New<IfcExtrudedAreaSolid>();
body_Opeinging.Depth = height;
body_Opeinging.SweptArea = rectOpening;
body_Opeinging.ExtrudedDirection = model.Instances.New<IfcDirection>();
body_Opeinging.ExtrudedDirection.SetXYZ(, , );
body_Opeinging.Position = model.Instances.New<IfcAxis2Placement3D>();
body_Opeinging.Position.Location = origin;
var shape__Opeinging = model.Instances.New<IfcShapeRepresentation>();
var modelContext__Opeinging = model.Instances.OfType<IfcGeometricRepresentationContext>().FirstOrDefault();
shape__Opeinging.ContextOfItems = modelContext__Opeinging;
shape__Opeinging.RepresentationType = "SweptSolid";
shape__Opeinging.RepresentationIdentifier = "Body";
shape__Opeinging.Items.Add(body_Opeinging); //创建产品定义并将模型几何添加到墙上
var rep_Opening = model.Instances.New<IfcProductDefinitionShape>();
rep_Opening.Representations.Add(shape__Opeinging);
m_OpeningEle.ObjectPlacement = lp_door;
m_OpeningEle.Representation = rep_Opening; var m_RelFills = model.Instances.New<IfcRelFillsElement>();
m_RelFills.RelatingOpeningElement = m_OpeningEle;
m_RelFills.RelatedBuildingElement = door;
var voidRel = model.Instances.New<IfcRelVoidsElement>();
voidRel.RelatedOpeningElement = m_OpeningEle;
voidRel.RelatingBuildingElement = wall; var ifcPropertySingleValue = model.Instances.New<IfcPropertySingleValue>(psv =>
{
psv.Name = "Reference";
psv.Description = "Reference";
psv.NominalValue = new IfcTimeMeasure(150.0);
psv.Unit = model.Instances.New<IfcSIUnit>(siu =>
{
siu.UnitType = IfcUnitEnum.TIMEUNIT;
siu.Name = IfcSIUnitName.SECOND;
});
});
//设置模型元素数量
var ifcPropertySet = model.Instances.New<IfcPropertySet>(ps =>
{
ps.Name = "Pset_DoorCommon";
ps.Description = "Property Set";
ps.HasProperties.Add(ifcPropertySingleValue); });
//需建立关系
model.Instances.New<IfcRelDefinesByProperties>(
rdbp =>
{
rdbp.Name = "Property Association";
rdbp.Description = "IfcPropertySet associated to wall";
rdbp.RelatedObjects.Add(door);
rdbp.RelatingPropertyDefinition = ifcPropertySet;
}); txn.Commit();
return door;
} }
static private IfcWindow CreateWindow(IfcStore model, IfcWallStandardCase wall, double length, double width, double height)
{
//启动事务
using (var txn = model.BeginTransaction("Create Window"))
{
var rectDoor = model.Instances.New<IfcRectangleProfileDef>();
rectDoor.ProfileType = IfcProfileTypeEnum.CURVE;
rectDoor.XDim = width - ;
rectDoor.YDim = length; var insertPoint = model.Instances.New<IfcCartesianPoint>();
insertPoint.SetXY(, ); //在任意位置插入
rectDoor.Position = model.Instances.New<IfcAxis2Placement2D>();
rectDoor.Position.Location = insertPoint; //模型区域实心
var body_door = model.Instances.New<IfcExtrudedAreaSolid>();
body_door.Depth = height;
body_door.SweptArea = rectDoor;
body_door.ExtrudedDirection = model.Instances.New<IfcDirection>();
body_door.ExtrudedDirection.SetXYZ(, , ); var origin = model.Instances.New<IfcCartesianPoint>();
origin.SetXYZ(, , );
//在模型中插入几何参数
body_door.Position = model.Instances.New<IfcAxis2Placement3D>();
body_door.Position.Location = origin; //创建一个定义形状来保存几何
var shape_door = model.Instances.New<IfcShapeRepresentation>();
var modelContext_door = model.Instances.OfType<IfcGeometricRepresentationContext>().FirstOrDefault();
shape_door.ContextOfItems = modelContext_door;
shape_door.RepresentationType = "SweptSolid";
shape_door.RepresentationIdentifier = "Body";
shape_door.Items.Add(body_door); //创建产品定义并将模型几何添加到墙上
var rep_door = model.Instances.New<IfcProductDefinitionShape>();
rep_door.Representations.Add(shape_door); // var door = model.Instances.New<IfcDoorStandardCase>();
//door.Name = "A Door";
//door.PredefinedType = IfcDoorTypeEnum.GATE;
//door.OperationType = IfcDoorTypeOperationEnum.DOUBLE_SWING_LEFT;
//door.OverallHeight = 400;
//door.OverallWidth = 400;
var door = model.Instances.New<IfcWindow>();
door.Name = "A Door";
door.PredefinedType = IfcWindowTypeEnum.WINDOW;
// door.OperationType = IfcDoorTypeOperationEnum.DOUBLE_SWING_LEFT;
door.OverallHeight = ;
door.OverallWidth = ;
door.PartitioningType = IfcWindowTypePartitioningEnum.SINGLE_PANEL; var windowType = model.Instances.New<IfcWindowType>();
windowType.Name = "Window";
windowType.Description = "ddddd";
windowType.PartitioningType = IfcWindowTypePartitioningEnum.SINGLE_PANEL;
var windowType_Rel= model.Instances.New<IfcRelDefinesByType>();
windowType_Rel.RelatedObjects.Add(door);
windowType_Rel.RelatingType = windowType;
var lp_door = model.Instances.New<IfcLocalPlacement>();
var wallplace = wall.ObjectPlacement;
var ax3D_door = model.Instances.New<IfcAxis2Placement3D>();
var origin2 = model.Instances.New<IfcCartesianPoint>();
origin2.SetXYZ(, , ); ax3D_door.RefDirection = model.Instances.New<IfcDirection>();
ax3D_door.RefDirection.SetXYZ(, , );//x轴
ax3D_door.Axis = model.Instances.New<IfcDirection>();
ax3D_door.Axis.SetXYZ(, , );//Z轴
ax3D_door.Location = origin2;
//lp_door.RelativePlacement = wallplace.RelativePlacement;
lp_door.RelativePlacement = ax3D_door;
lp_door.PlacementRelTo = wallplace;
door.ObjectPlacement = lp_door;
door.Representation = rep_door;
// var m_door_style = model.Instances.New<IfcSurfaceStyle>();
////////////////////////////////////////////////////////////////////
var m_OpeningEle = model.Instances.New<IfcOpeningElement>();
m_OpeningEle.Name = "My Openings";
m_OpeningEle.PredefinedType = IfcOpeningElementTypeEnum.OPENING; var rectOpening = model.Instances.New<IfcRectangleProfileDef>();
rectOpening.ProfileType = IfcProfileTypeEnum.AREA;
rectOpening.XDim = width;
rectOpening.YDim = length;
rectOpening.Position = model.Instances.New<IfcAxis2Placement2D>();
rectOpening.Position.Location = insertPoint; //模型区域实心
var body_Opeinging = model.Instances.New<IfcExtrudedAreaSolid>();
body_Opeinging.Depth = height;
body_Opeinging.SweptArea = rectOpening;
body_Opeinging.ExtrudedDirection = model.Instances.New<IfcDirection>();
body_Opeinging.ExtrudedDirection.SetXYZ(, , );
body_Opeinging.Position = model.Instances.New<IfcAxis2Placement3D>();
body_Opeinging.Position.Location = origin;
var shape__Opeinging = model.Instances.New<IfcShapeRepresentation>();
var modelContext__Opeinging = model.Instances.OfType<IfcGeometricRepresentationContext>().FirstOrDefault();
shape__Opeinging.ContextOfItems = modelContext__Opeinging;
shape__Opeinging.RepresentationType = "SweptSolid";
shape__Opeinging.RepresentationIdentifier = "Body";
shape__Opeinging.Items.Add(body_Opeinging); //创建产品定义并将模型几何添加到墙上
var rep_Opening = model.Instances.New<IfcProductDefinitionShape>();
rep_Opening.Representations.Add(shape__Opeinging);
m_OpeningEle.ObjectPlacement = lp_door;
m_OpeningEle.Representation = rep_Opening; var m_RelFills = model.Instances.New<IfcRelFillsElement>();
m_RelFills.RelatingOpeningElement = m_OpeningEle;
m_RelFills.RelatedBuildingElement = door;
var voidRel = model.Instances.New<IfcRelVoidsElement>();
voidRel.RelatedOpeningElement = m_OpeningEle;
voidRel.RelatingBuildingElement = wall; var material98 = model.Instances.New<IfcMaterial>();
material98.Name = "Glass";
var material100 = model.Instances.New<IfcMaterial>();
material100.Name = "Wood"; var n_ifcMaterialConstituentSet = model.Instances.New<IfcMaterialConstituentSet>();
var n_ifcMaterialConstituent = model.Instances.New<IfcMaterialConstituent>();
n_ifcMaterialConstituent.Category = "Framing";
n_ifcMaterialConstituent.Material = material98;
var n_ifcMaterialConstituent100 = model.Instances.New<IfcMaterialConstituent>();
n_ifcMaterialConstituent100.Category = "Framing";
n_ifcMaterialConstituent100.Material = material100;
//n_ifcMaterialConstituent.Model = door;
n_ifcMaterialConstituentSet.MaterialConstituents.Add(n_ifcMaterialConstituent);
n_ifcMaterialConstituentSet.MaterialConstituents.Add(n_ifcMaterialConstituent100);
var ifcRelAssociatesMaterial = model.Instances.New<IfcRelAssociatesMaterial>();
ifcRelAssociatesMaterial.RelatingMaterial = n_ifcMaterialConstituentSet;
ifcRelAssociatesMaterial.RelatedObjects.Add(door); var ifcPropertySingleValue = model.Instances.New<IfcPropertySingleValue>(psv =>
{
psv.Name = "Reference";
psv.Description = "Reference";
psv.NominalValue = new IfcTimeMeasure(150.0);
psv.Unit = model.Instances.New<IfcSIUnit>(siu =>
{
siu.UnitType = IfcUnitEnum.TIMEUNIT;
siu.Name = IfcSIUnitName.SECOND;
});
});
var ifcPropertySingleValue2 = model.Instances.New<IfcPropertySingleValue>(psv =>
{
psv.Name = "FireRating";
psv.Description = ""; });
var ifcPropertySingleValue3 = model.Instances.New<IfcPropertySingleValue>(psv =>
{
psv.Name = "AcousticRating";
psv.Description = "AcousticRating"; });
var ifcPropertySingleValue4 = model.Instances.New<IfcPropertySingleValue>(psv =>
{
psv.Name = "IsExternal";
psv.Description = "IsExternal";
psv.NominalValue = new IfcBoolean(true); });
var ifcPropertySingleValue5 = model.Instances.New<IfcPropertySingleValue>(psv =>
{
psv.Name = "Infiltration";
psv.Description = "Infiltration";
psv.NominalValue = new IfcReal(0.3); });
var ifcPropertySingleValue6 = model.Instances.New<IfcPropertySingleValue>(psv =>
{
psv.Name = "ThermalTransmittance";
psv.Description = "ThermalTransmittance";
psv.NominalValue = new IfcReal(0.24); });
//设置模型元素数量
var ifcPropertySet = model.Instances.New<IfcPropertySet>(ps =>
{
ps.Name = "Pset_WindowCommon";
ps.Description = "Property Set";
ps.HasProperties.Add(ifcPropertySingleValue);
ps.HasProperties.Add(ifcPropertySingleValue2);
ps.HasProperties.Add(ifcPropertySingleValue3);
ps.HasProperties.Add(ifcPropertySingleValue4);
ps.HasProperties.Add(ifcPropertySingleValue5);
ps.HasProperties.Add(ifcPropertySingleValue6);
});
//需建立关系
model.Instances.New<IfcRelDefinesByProperties>(
rdbp =>
{
rdbp.Name = "Property Association";
rdbp.Description = "IfcPropertySet associated to wall";
rdbp.RelatedObjects.Add(door);
rdbp.RelatingPropertyDefinition = ifcPropertySet;
}); txn.Commit();
return door;
} }
/// <summary>
/// 给墙添加属性
/// </summary>
/// <param name="model">XbimModel</param>
/// <param name="wall"></param>
static private void AddPropertiesToWall(IfcStore model, IfcWallStandardCase wall)
{
using (var txn = model.BeginTransaction("Create Wall"))
{
CreateElementQuantity(model, wall);
CreateSimpleProperty(model, wall);
txn.Commit();
}
} private static void CreateSimpleProperty(IfcStore model, IfcWallStandardCase wall)
{
var ifcPropertySingleValue = model.Instances.New<IfcPropertySingleValue>(psv =>
{
psv.Name = "IfcPropertySingleValue:Time";
psv.Description = "";
psv.NominalValue = new IfcTimeMeasure(150.0);
psv.Unit = model.Instances.New<IfcSIUnit>(siu =>
{
siu.UnitType = IfcUnitEnum.TIMEUNIT;
siu.Name = IfcSIUnitName.SECOND;
});
});
var ifcPropertyEnumeratedValue = model.Instances.New<IfcPropertyEnumeratedValue>(pev =>
{
pev.Name = "IfcPropertyEnumeratedValue:Music";
pev.EnumerationReference = model.Instances.New<IfcPropertyEnumeration>(pe =>
{
pe.Name = "Notes";
pe.EnumerationValues.Add(new IfcLabel("Do"));
pe.EnumerationValues.Add(new IfcLabel("Re"));
pe.EnumerationValues.Add(new IfcLabel("Mi"));
pe.EnumerationValues.Add(new IfcLabel("Fa"));
pe.EnumerationValues.Add(new IfcLabel("So"));
pe.EnumerationValues.Add(new IfcLabel("La"));
pe.EnumerationValues.Add(new IfcLabel("Ti"));
});
pev.EnumerationValues.Add(new IfcLabel("Do"));
pev.EnumerationValues.Add(new IfcLabel("Re"));
pev.EnumerationValues.Add(new IfcLabel("Mi")); });
var ifcPropertyBoundedValue = model.Instances.New<IfcPropertyBoundedValue>(pbv =>
{
pbv.Name = "IfcPropertyBoundedValue:Mass";
pbv.Description = "";
pbv.UpperBoundValue = new IfcMassMeasure(5000.0);
pbv.LowerBoundValue = new IfcMassMeasure(1000.0);
pbv.Unit = model.Instances.New<IfcSIUnit>(siu =>
{
siu.UnitType = IfcUnitEnum.MASSUNIT;
siu.Name = IfcSIUnitName.GRAM;
siu.Prefix = IfcSIPrefix.KILO;
});
}); var definingValues = new List<IfcReal> { new IfcReal(100.0), new IfcReal(200.0), new IfcReal(400.0), new IfcReal(800.0), new IfcReal(1600.0), new IfcReal(3200.0), };
var definedValues = new List<IfcReal> { new IfcReal(20.0), new IfcReal(42.0), new IfcReal(46.0), new IfcReal(56.0), new IfcReal(60.0), new IfcReal(65.0), };
var ifcPropertyTableValue = model.Instances.New<IfcPropertyTableValue>(ptv =>
{
ptv.Name = "IfcPropertyTableValue:Sound";
foreach (var item in definingValues)
{
ptv.DefiningValues.Add(item);
}
foreach (var item in definedValues)
{
ptv.DefinedValues.Add(item);
}
ptv.DefinedUnit = model.Instances.New<IfcContextDependentUnit>(cd =>
{
cd.Dimensions = model.Instances.New<IfcDimensionalExponents>(de =>
{
de.LengthExponent = ;
de.MassExponent = ;
de.TimeExponent = ;
de.ElectricCurrentExponent = ;
de.ThermodynamicTemperatureExponent = ;
de.AmountOfSubstanceExponent = ;
de.LuminousIntensityExponent = ;
});
cd.UnitType = IfcUnitEnum.FREQUENCYUNIT;
cd.Name = "dB";
}); }); var listValues = new List<IfcLabel> { new IfcLabel("Red"), new IfcLabel("Green"), new IfcLabel("Blue"), new IfcLabel("Pink"), new IfcLabel("White"), new IfcLabel("Black"), };
var ifcPropertyListValue = model.Instances.New<IfcPropertyListValue>(plv =>
{
plv.Name = "IfcPropertyListValue:Colours";
foreach (var item in listValues)
{
plv.ListValues.Add(item);
}
}); var ifcMaterial = model.Instances.New<IfcMaterial>(m =>
{
m.Name = "Brick";
});
var ifcPrValueMaterial = model.Instances.New<IfcPropertyReferenceValue>(prv =>
{
prv.Name = "IfcPropertyReferenceValue:Material";
prv.PropertyReference = ifcMaterial;
}); var ifcMaterialList = model.Instances.New<IfcMaterialList>(ml =>
{
ml.Materials.Add(ifcMaterial);
ml.Materials.Add(model.Instances.New<IfcMaterial>(m =>{m.Name = "Cavity";}));
ml.Materials.Add(model.Instances.New<IfcMaterial>(m => { m.Name = "Block"; }));
}); var ifcMaterialLayer = model.Instances.New<IfcMaterialLayer>(ml =>
{
ml.Material = ifcMaterial;
ml.LayerThickness = 100.0;
});
var ifcPrValueMatLayer = model.Instances.New<IfcPropertyReferenceValue>(prv =>
{
prv.Name = "IfcPropertyReferenceValue:MaterialLayer";
prv.PropertyReference = ifcMaterialLayer;
}); var ifcDocumentReference = model.Instances.New<IfcDocumentReference>(dr =>
{
dr.Name = "Document";
dr.Location = "c://Documents//TheDoc.Txt";
});
var ifcPrValueRef = model.Instances.New<IfcPropertyReferenceValue>(prv =>
{
prv.Name = "IfcPropertyReferenceValue:Document";
prv.PropertyReference = ifcDocumentReference;
}); var ifcTimeSeries = model.Instances.New<IfcRegularTimeSeries>(ts =>
{
ts.Name = "Regular Time Series";
ts.Description = "Time series of events";
ts.StartTime = new IfcDateTime("2015-02-14T12:01:01");
ts.EndTime = new IfcDateTime("2015-05-15T12:01:01");
ts.TimeSeriesDataType = IfcTimeSeriesDataTypeEnum.CONTINUOUS;
ts.DataOrigin = IfcDataOriginEnum.MEASURED;
ts.TimeStep = ; //7 days in secs
}); var ifcPrValueTimeSeries = model.Instances.New<IfcPropertyReferenceValue>(prv =>
{
prv.Name = "IfcPropertyReferenceValue:TimeSeries";
prv.PropertyReference = ifcTimeSeries;
}); var ifcAddress = model.Instances.New<IfcPostalAddress>(a =>
{
a.InternalLocation = "Room 101";
a.AddressLines.AddRange(new[] { new IfcLabel("12 New road"), new IfcLabel("DoxField" ) });
a.Town = "Sunderland";
a.PostalCode = "DL01 6SX";
});
var ifcPrValueAddress = model.Instances.New<IfcPropertyReferenceValue>(prv =>
{
prv.Name = "IfcPropertyReferenceValue:Address";
prv.PropertyReference = ifcAddress;
});
var ifcTelecomAddress = model.Instances.New<IfcTelecomAddress>(a =>
{
a.TelephoneNumbers.Add(new IfcLabel("01325 6589965"));
a.ElectronicMailAddresses.Add(new IfcLabel("bob@bobsworks.com"));
});
var ifcPrValueTelecom = model.Instances.New<IfcPropertyReferenceValue>(prv =>
{
prv.Name = "IfcPropertyReferenceValue:Telecom";
prv.PropertyReference = ifcTelecomAddress;
}); //设置模型元素数量
var ifcPropertySet = model.Instances.New<IfcPropertySet>(ps =>
{
ps.Name = "Test:IfcPropertySet";
ps.Description = "Property Set";
ps.HasProperties.Add(ifcPropertySingleValue);
ps.HasProperties.Add(ifcPropertyEnumeratedValue);
ps.HasProperties.Add(ifcPropertyBoundedValue);
ps.HasProperties.Add(ifcPropertyTableValue);
ps.HasProperties.Add(ifcPropertyListValue);
ps.HasProperties.Add(ifcPrValueMaterial);
ps.HasProperties.Add(ifcPrValueMatLayer);
ps.HasProperties.Add(ifcPrValueRef);
ps.HasProperties.Add(ifcPrValueTimeSeries);
ps.HasProperties.Add(ifcPrValueAddress);
ps.HasProperties.Add(ifcPrValueTelecom);
}); //需建立关系
model.Instances.New<IfcRelDefinesByProperties>(rdbp =>
{
rdbp.Name = "Property Association";
rdbp.Description = "IfcPropertySet associated to wall";
rdbp.RelatedObjects.Add(wall);
rdbp.RelatingPropertyDefinition = ifcPropertySet;
});
} private static void CreateElementQuantity(IfcStore model, IfcWallStandardCase wall)
{
//创建模型元素数量
//首先我们需模型简单物理量,首先将使用模型量长度
var ifcQuantityArea = model.Instances.New<IfcQuantityLength>(qa =>
{
qa.Name = "IfcQuantityArea:Area";
qa.Description = "";
qa.Unit = model.Instances.New<IfcSIUnit>(siu =>
{
siu.UnitType = IfcUnitEnum.LENGTHUNIT;
siu.Prefix = IfcSIPrefix.MILLI;
siu.Name = IfcSIUnitName.METRE;
});
qa.LengthValue = 100.0; });
//上下文相关单元的数量计数
var ifcContextDependentUnit = model.Instances.New<IfcContextDependentUnit>(cd =>
{
cd.Dimensions = model.Instances.New<IfcDimensionalExponents>(de =>
{
de.LengthExponent = ;
de.MassExponent = ;
de.TimeExponent = ;
de.ElectricCurrentExponent = ;
de.ThermodynamicTemperatureExponent = ;
de.AmountOfSubstanceExponent = ;
de.LuminousIntensityExponent = ;
});
cd.UnitType = IfcUnitEnum.LENGTHUNIT;
cd.Name = "Elephants";
});
var ifcQuantityCount = model.Instances.New<IfcQuantityCount>(qc =>
{
qc.Name = "IfcQuantityCount:Elephant";
qc.CountValue = ;
qc.Unit = ifcContextDependentUnit;
}); //使用转换单位
var ifcConversionBasedUnit = model.Instances.New<IfcConversionBasedUnit>(cbu =>
{
cbu.ConversionFactor = model.Instances.New<IfcMeasureWithUnit>(mu =>
{
mu.ValueComponent = new IfcRatioMeasure(25.4);
mu.UnitComponent = model.Instances.New<IfcSIUnit>(siu =>
{
siu.UnitType = IfcUnitEnum.LENGTHUNIT;
siu.Prefix = IfcSIPrefix.MILLI;
siu.Name = IfcSIUnitName.METRE;
}); });
cbu.Dimensions = model.Instances.New<IfcDimensionalExponents>(de =>
{
de.LengthExponent = ;
de.MassExponent = ;
de.TimeExponent = ;
de.ElectricCurrentExponent = ;
de.ThermodynamicTemperatureExponent = ;
de.AmountOfSubstanceExponent = ;
de.LuminousIntensityExponent = ;
});
cbu.UnitType = IfcUnitEnum.LENGTHUNIT;
cbu.Name = "Inch";
});
var ifcQuantityLength = model.Instances.New<IfcQuantityLength>(qa =>
{
qa.Name = "IfcQuantityLength:Length";
qa.Description = "";
qa.Unit = ifcConversionBasedUnit;
qa.LengthValue = 24.0;
}); //lets create the IfcElementQuantity
var ifcElementQuantity = model.Instances.New<IfcElementQuantity>(eq =>
{
eq.Name = "Test:IfcElementQuantity";
eq.Description = "Measurement quantity";
eq.Quantities.Add(ifcQuantityArea);
eq.Quantities.Add(ifcQuantityCount);
eq.Quantities.Add(ifcQuantityLength);
}); //下步 建议关系
model.Instances.New<IfcRelDefinesByProperties>(rdbp =>
{
rdbp.Name = "Area Association";
rdbp.Description = "IfcElementQuantity associated to wall";
rdbp.RelatedObjects.Add(wall);
rdbp.RelatingPropertyDefinition = ifcElementQuantity;
});
} }
Code
这个代码是有bug的,目前已经解决!
参考资料:
IFC4国内说明文档:http://www.vfkjsd.cn/ifc/ifc4/index.htm
IFC4官方说明文档:http://www.buildingsmart-tech.org/ifc/IFC4/final/html/link/ifcarbitraryclosedprofiledef.htm
xBIM 应用与学习:https://www.cnblogs.com/w2011/p/8407286.html
xBIM之二:构建墙和门窗的更多相关文章
- xBIM 基础05 3D墙案例
系列目录 [已更新最新开发文章,点击查看详细] 使用编码的形式去生成一堵墙的模型需要做很多的工作. using System; using System.Collections.Generic ...
- spring boot 学习笔记(二) 构建web支持jsp
一.必须将项目打包成war包 <packaging>war</packaging> 二.pom.xml加入依赖包 <dependency> <groupId& ...
- mybatis源码解读(二)——构建Configuration对象
Configuration 对象保存了所有mybatis的配置信息,主要包括: ①. mybatis-configuration.xml 基础配置文件 ②. mapper.xml 映射器配置文件 1. ...
- grafana二次开发
grafana官方地址: https://github.com/grafana/grafana 开发文档:http://docs.grafana.org/project/building_from_s ...
- maven打包步骤_maven 构建项目
maven打包 1:先在pom文件中添加下面配置 jar <build> <plugins> <!-- compiler插件, 设定 ...
- blfs(systemd版本)学习笔记-构建gnome桌面系统后的配置及安装的应用
我的邮箱地址:zytrenren@163.com欢迎大家交流学习纠错! 一.构建安装ibus-libpinyin的笔记地址:https://www.cnblogs.com/renren-study-n ...
- 利用openssl构建根证书-服务器证书-客户证书
利用openssl构建根证书-服务器证书-客户证书 OpenSSL功能远胜于KeyTool,可用于根证书,服务器证书和客户证书的管理 一.构建根证书 1.构建根证书前,需要构建随机数文件(.rand) ...
- 《机器学习实战》学习笔记第十二章 —— FP-growth算法
主要内容: 一. FP-growth算法简介 二.构建FP树 三.从一颗FP树中挖掘频繁项集 一. FP-growth算法简介 1.上次提到可以用Apriori算法来提取频繁项集,但是Aprior ...
- 基于Dockerfile 构建redis5.0.0(包括持久化)及RedisDestopManager 监控
一 创建Dockerfile [root@zxmrlc docker]# mkdir redis [root@zxmrlc docker]# cd redis && touch Doc ...
随机推荐
- Kubernetes 安全概念详解
Kubernetes 安全框架 API 认证三关 • 访问K8S集群的资源需要过三关:认证.鉴权.准入控制• 普通用户若要安全访问集群API Server,往往需要证书.Token 或者用户名+密码 ...
- Kubernetes RBAC授权普通用户对命名空间访问权限
Kubernetes RBAC授权普通用户对命名空间访问权限 官方文档:https://www.cnblogs.com/xiangsikai/p/11413970.html kind: Role ap ...
- Logstash:多个配置文件(conf)
Logstash:多个配置文件(conf) 对于多个配置的处理方法,有多个处理方法: 多个pipeline 一个pipleline处理多个配置文件 一个pipeline含有一个逻辑的数据流,它从inp ...
- 【Python】itertools之product函数
[转载]源博客 product 用于求多个可迭代对象的笛卡尔积(Cartesian Product),它跟嵌套的 for 循环等价.即: product(A, B) 和 ((x,y) for x in ...
- 2019-7-29-win10-UWP-使用-MD5算法
原文:2019-7-29-win10-UWP-使用-MD5算法 title author date CreateTime categories win10 UWP 使用 MD5算法 lindexi 2 ...
- 夜神模拟器怎么连接adb
夜神模拟器连接不了adb的原因主要是adb的版本与夜神模拟器adb版本不一致造成的,具体的解决办法请看下面的操作步骤. 工具/原料 电脑 安装了夜神模拟器 方法/步骤 1 使用快捷键win + ...
- tomcat的基本应用
1.JVM基本介绍 JAVA编译型 ---> 编译 C 编译型---> linux --->编译一次 windows --->编译一次 macos ubuntu 跨平台 移值型 ...
- vue-router简易的实现原理
class VueRouter { constructor(options) { this.$options = options; this.routeMap = {}; // 路由响应式 this. ...
- 使用Javamail实现邮件发送功能
目录 相关的包 编写工具类 环境说明 @(使用Javamail实现邮件发送功能) 相关的包 activation.jar javax.mail.jar mail包建议使用高版本写的包,否则可能会发空白 ...
- vue路由跳转传参的两种方法
路由跳转: this.$router.push({ name: '工单列表', params: {p_camera_dev_name: 'xxx'} }); 使二级菜单呈点击状态: $('[index ...