使用java解析ifc并获取数据(树形结构)

ifc解析

 

import java.io.File;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.TreeMap;

import javax.swing.tree.DefaultMutableTreeNode;

import com.vfsd.demo.IfcSpatialStructure;
import com.vfsd.ifc2x3tc1.IfcBuildingStorey;
import com.vfsd.ifc2x3tc1.IfcWall;
import com.vfsd.ifcmodel.IfcModel;

public class Test {
    public static void main(String[] args) throws Exception{
        IfcModel ifcModel = new IfcModel();
        //File file = new File("C:\\Users\\new\\Desktop\\项目1.ifc");
        File file  = new File("C:\\Users\\new\\Desktop\\项目2016-0002.ifc");
        ifcModel.readStepFile(file);

        DefaultMutableTreeNode rootTreeNode = new DefaultMutableTreeNode("no model loaded");

        Enumeration<?> enumeration;
        enumeration=rootTreeNode.depthFirstEnumeration();//以深度遍历节点
        //enumeration=rootTreeNode.preorderEnumeration();//按前序遍历根节点
        //enumeration=rootTreeNode.breadthFirstEnumeration();//以广度遍历节点
        //enumeration=rootTreeNode.postorderEnumeration();//按后序遍历节点
        //enumeration=rootTreeNode.children();//遍历该节点的所有子节点.

        //知道了遍历方式,开始遍历.
        while(enumeration.hasMoreElements()){ 
            //遍历枚举对象.
            //先定义一个节点变量.
            DefaultMutableTreeNode node;
            node=(DefaultMutableTreeNode) enumeration.nextElement();//将节点名称给node.
            //根据级别输出占位符.
            for(int l=0;l<node.getLevel();l++){
                System.out.print("---");
            }
            //System.out.println(node.getUserObject()+"       "+node.getUserObject().getClass().getName()+"    "+node.getUserObject().getClass().getSimpleName());//输入节点标签.
            System.out.println(node.getUserObject());
        }

    }

}

 

 

##########3

posted @ 2017-03-06 14:38  西北逍遥  阅读(2255)  评论(3编辑  收藏  举报