ĐỊNH DẠNG IFC CƠ BẢN
IFC (Industry Foundation Classes) là một định dạng tệp mở được sử dụng để trao đổi dữ liệu mô hình thông tin công trình (BIM). IFC được phát triển bởi buildingSMART và hỗ trợ khả năng tương tác giữa các phần mềm BIM khác nhau.
Cấu trúc cơ bản của IFC:
-
Entities (Thực thể):
IfcProject
: Đại diện cho dự án.IfcSite
: Định nghĩa khu vực địa điểm.IfcBuilding
: Đại diện cho một tòa nhà.IfcBuildingStorey
: Tầng của tòa nhà.IfcWall
,IfcSlab
,IfcBeam
,IfcColumn
,IfcDoor
,IfcWindow
: Các thành phần kiến trúc.
-
Mô hình hóa hình học:
IfcCartesianPoint
: Điểm trong không gian 2D/3D.IfcPolyline
: Định nghĩa đường Polyline.IfcExtrudedAreaSolid
: Khối đặc đùn từ mặt phẳng.
1️⃣ VẼ HÌNH KHỐI CƠ BẢN BẰNG C# VÀ .NET
Dưới đây là ví dụ sử dụng Windows Forms + OpenTK để vẽ khối hộp cơ bản trong C#.
CÀI ĐẶT THƯ VIỆN
Cài đặt OpenTK.GLControl qua NuGet:
CODE MẪU C#
Code:using OpenTK;
using OpenTK.Graphics.OpenGL;
using System;
using System.Windows.Forms;
using Application = System.Windows.Forms.Application;
public class MainForm : Form
{
//NuGet\Install-Package OpenTK -Version 3.3.3
//NuGet\Install-Package OpenTK.GLControl -Version 1.1.2225
private GLControl glControl;
public MainForm()
{
//
this.Text = "Vẽ Hình Khối Cơ Bản";
this.Width = 800;
this.Height = 600;
glControl = new GLControl();
glControl.Dock = DockStyle.Fill;
glControl.Paint += GlControl_Paint;
glControl.TopLevel = false;
this.Controls.Add(glControl);
glControl.Show();
}
private void GlControl_Paint(object sender, PaintEventArgs e)
{
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
GL.MatrixMode(MatrixMode.Modelview);
GL.LoadIdentity();
GL.Begin(PrimitiveType.Quads);
GL.Color3(1.0, 0.0, 0.0); GL.Vertex3(-0.5, -0.5, 0.5);
GL.Color3(0.0, 1.0, 0.0); GL.Vertex3(0.5, -0.5, 0.5);
GL.Color3(0.0, 0.0, 1.0); GL.Vertex3(0.5, 0.5, 0.5);
GL.Color3(1.0, 1.0, 0.0); GL.Vertex3(-0.5, 0.5, 0.5);
GL.End();
glControl.SwapBuffers();
}
[STAThread]
private static void Main()
{
Application.EnableVisualStyles();
Application.Run(new MainForm());
}
}
GIẢI THÍCH:
- GLControl: Điều khiển đồ họa OpenGL trong WinForms.
- GL.Begin(PrimitiveType.Quads): Vẽ mặt trước của khối hộp.
- GL.Color3(): Thiết lập màu sắc cho từng đỉnh.
- GL.Vertex3(): Định nghĩa tọa độ của đỉnh.
2️⃣CODE MẪU: XUẤT IFC TỪ C#
Để mở rộng ứng dụng vẽ hình khối cơ bản và hỗ trợ xuất ra định dạng IFC, ta có thể sử dụng xBIM Toolkit, một thư viện .NET mạnh mẽ để tạo và xử lý tệp IFC.
CÀI ĐẶT THƯ VIỆN xBIM
Cài đặt thư viện xBIM qua NuGet:
Install-Package Xbim.Essentials
Install-Package Xbim.Geometry
Install-Package Xbim.Ifc
Dưới đây là một đoạn mã để tạo một tệp IFC đơn giản chứa một khối hộp (IfcWall) và lưu thành tệp .ifc
Code:using System; using System.Linq; using Xbim.Common; using Xbim.Common.Step21; using Xbim.Ifc; using Xbim.Ifc4.GeometricConstraintResource; using Xbim.Ifc4.Kernel; using Xbim.Ifc4.RepresentationResource; using Xbim.Ifc4.SharedBldgElements; using Xbim.IO; namespace HelloWall { internal class Program { /// <summary> /// This sample demonstrates the minimum steps to create a compliant IFC model that contains a single standard case wall /// </summary> /// private static void Main() { string filePath = "output.ifc"; using (var model = CreateandInitModel(filePath)) { using (var txn = model.BeginTransaction("Add Wall")) { var wall = CreateWall(model); model.Instances.Append(wall); txn.Commit(); } model.SaveAs(filePath, StorageType.Ifc); Console.WriteLine($"IFC file saved: {filePath}"); } } private static IfcStore CreateandInitModel(string projectName) { //first we need to set up some credentials for ownership of data in the new model var credentials = new XbimEditorCredentials { ApplicationDevelopersName = "xBimTeam", ApplicationFullName = "Hello Wall Application", ApplicationIdentifier = "HelloWall.exe", ApplicationVersion = "1.0", EditorsFamilyName = "Team", EditorsGivenName = "xBIM", EditorsOrganisationName = "xBimTeam" }; //now we can create an IfcStore, it is in Ifc4 format and will be held in memory rather than in a database //database is normally better in performance terms if the model is large >50MB of Ifc or if robust transactions are required var model = IfcStore.Create(credentials, XbimSchemaVersion.Ifc4, XbimStoreType.InMemoryModel); //Begin a transaction as all changes to a model are ACID using (var txn = model.BeginTransaction("Initialise Model")) { //create a project var project = model.Instances.New<IfcProject>(); //set the units to SI (mm and metres) project.Initialize(ProjectUnits.SIUnitsUK); project.Name = projectName; //now commit the changes, else they will be rolled back at the end of the scope of the using statement txn.Commit(); } return model; } private static IfcWall CreateWall(IModel model) { return model.Instances.New<IfcWall>(w => { w.Name = "Basic Wall"; w.ObjectPlacement = model.Instances.New<IfcLocalPlacement>(); w.Representation = model.Instances.New<IfcProductDefinitionShape>(); }); } } }
Không có nhận xét nào:
Đăng nhận xét