IfcEngine+VS2015工程配置指南

2016-12-14  本文已影响0人  qlaiaqu

目的

本文档说明了如何基于IfcEngine与VS2015配置IFC的开发环境。IfcEngine支持VS2008,vs2010,vs2013,vs2o15可以根据自己的实际情况选择对应的版本。

下载

VS2015

vs2015作为软件集成开发环境。
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已经出了多个版本,目前选择主流版本ifc 2x3。官方BuildingSmart提供Ifc用Express语言编写的Schema文件,IfcEngine通过载入Schema文件,用以解析Ifc文件。
http://www.buildingsmart-tech.org/specifications/ifc-releases/ifc2x3-tc1-release

1.png

开发环境配置

新建工程

打开VS2015,选择File->New->Project,按如下图片中指示选择工程类型:


2.png

点击OK,即可创建工程,右键项目,选择Build,即可完成编译。

环境配置

工程建立完毕,需要将IfcEngine,Schema文件和Ifc文件拷贝到指定的目录。

ifcengine文件拷贝

ifcengine支持多个版本的vs,此处根据需要选择相应版本即可,此处是vs2015,我选择32bit-Windows-Vs2013/ifcengine.dll,拷贝到Projects\IfcTest\IfcTest\bin\Debug

3.png

schema文件拷贝

schema(IFC2X3_TC1.exp)文件放置到Projects\IfcTest\IfcTest\bin\Debug目录下

ifc文件拷贝

ifc文件放置到Projects\IfcTest\IfcTest\bin\Debug目录下

开发

开发分成两步骤,Api导入,Schema/ifc文件载入

Api导入

IfcEngine使用C++编写,并生成DLL动态库。C#使用DLL动态库的时候,需要首先声明从DLL动态库中导入的函数名称。在IfcEngine官方提供的文档中,已经有函数导入的实例,如图所示:

![JS]XX7(R8@5RL`WN~8IFSSQ.png](https://img.haomeiwen.com/i2657968/98e768dbaf65ef79.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

代码编写

Api导入完毕之后,就可以使用了,所有代码如下:

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";

        //导入函数列表
        [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");

                //关闭Ifc文件
                sdaiCloseModel(model);
            }
            else
            {
                Console.Write("Load Failed!\n");
            }
        }

        static void Main(string[] args)
        {
            Program program = new Program();
            program.Parse();
        }
    }
}

配置运行

点击Ctrl+F5,开始运行,看到如下窗口,表示环境配置成功:

4.png
上一篇下一篇

猜你喜欢

热点阅读