目的
本文檔說明了如何基于IfcEngine與VS2015配置IFC的開發(fā)環(huán)境。IfcEngine支持VS2008,vs2010,vs2013,vs2o15可以根據(jù)自己的實際情況選擇對應(yīng)的版本。
下載
VS2015
vs2015作為軟件集成開發(fā)環(huán)境。
http://download.microsoft.com/download/5/d/1/5d1ec81e-bc59-448f-9ab6-27636d5cc18a/vs2015.3.com_chs.iso
IfcEngine
庫:http://rdf.bg/ifcenginedll/ifcenginedll.zip
示例代碼:http://rdf.bg/ifcenginedll/ifcenginedllpackage.zip
官方文檔:http://rdf.bg/ifcdoc/CP64/sdaiOpenModelBN.html
Ifc Schema
目前Ifc已經(jīng)出了多個版本,目前選擇主流版本ifc 2x3。官方BuildingSmart提供Ifc用Express語言編寫的Schema文件,IfcEngine通過載入Schema文件,用以解析Ifc文件。
http://www.buildingsmart-tech.org/specifications/ifc-releases/ifc2x3-tc1-release

開發(fā)環(huán)境配置
新建工程
打開VS2015,選擇File->New->Project,按如下圖片中指示選擇工程類型:

點擊OK,即可創(chuàng)建工程,右鍵項目,選擇Build,即可完成編譯。
環(huán)境配置
工程建立完畢,需要將IfcEngine,Schema文件和Ifc文件拷貝到指定的目錄。
ifcengine文件拷貝
ifcengine支持多個版本的vs,此處根據(jù)需要選擇相應(yīng)版本即可,此處是vs2015,我選擇32bit-Windows-Vs2013/ifcengine.dll,拷貝到Projects\IfcTest\IfcTest\bin\Debug

schema文件拷貝
schema(IFC2X3_TC1.exp)文件放置到Projects\IfcTest\IfcTest\bin\Debug目錄下
ifc文件拷貝
ifc文件放置到Projects\IfcTest\IfcTest\bin\Debug目錄下
開發(fā)
開發(fā)分成兩步驟,Api導(dǎo)入,Schema/ifc文件載入
Api導(dǎo)入
IfcEngine使用C++編寫,并生成DLL動態(tài)庫。C#使用DLL動態(tài)庫的時候,需要首先聲明從DLL動態(tài)庫中導(dǎo)入的函數(shù)名稱。在IfcEngine官方提供的文檔中,已經(jīng)有函數(shù)導(dǎo)入的實例,如圖所示:
![JS]XX7(R8@5RL`WN~8IFSSQ.png](http://upload-images.jianshu.io/upload_images/2657968-98e768dbaf65ef79.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
代碼編寫
Api導(dǎo)入完畢之后,就可以使用了,所有代碼如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
namespace IfcTest
{
class Program
{
//dll文件路徑
public const string IFCEngineDLL = @"IFCEngine.dll";
//導(dǎo)入函數(shù)列表
[DllImport(IFCEngineDLL, EntryPoint = "sdaiOpenModelBN")]
public static extern Int32 sdaiOpenModelBN(Int32 repository, string fileName, string schemaName);
[DllImport(IFCEngineDLL, EntryPoint = "sdaiOpenModelBN")]
public static extern Int32 sdaiOpenModelBN(Int32 repository, byte[] fileName, byte[] schemaName);
[DllImport(IFCEngineDLL, EntryPoint = "sdaiCloseModel")]
public static extern void sdaiCloseModel(Int32 model);
void Parse()
{
//ifc文件路徑
string ifcFileName = "creator.ifc";
//載入Ifc文件
Int32 model = sdaiOpenModelBN(0, ifcFileName, "IFC2X3_TC1.exp");
if (model != 0)
{
Console.Write("Load Succeesed!\n");
//關(guān)閉Ifc文件
sdaiCloseModel(model);
}
else
{
Console.Write("Load Failed!\n");
}
}
static void Main(string[] args)
{
Program program = new Program();
program.Parse();
}
}
}
配置運行
點擊Ctrl+F5,開始運行,看到如下窗口,表示環(huán)境配置成功:
