public void CreateItem(IFCItem parent, IntPtr ifcID, string ifcType, string globalID, string name, string desc)
        {
            this.parent = parent;
            this.next = null;
            this.child = null;
            this.globalID = globalID;
            this.ifcID = ifcID;
            this.ifcType = ifcType;
            this.description = desc;
            this.name = name;

            if (parent != null) {
                if (parent.child == null) {
                    parent.child = this;
                } else {
                    IFCItem NextChild = parent;

                    while (true) {
                        if (NextChild.next == null) {
                            NextChild.next = this;
                            break;
                        } else {
                            NextChild = NextChild.next;
                        }

                    }

                }

            }
        }
Exemple #2
0
        /// <summary>
        /// Helper
        /// </summary>
        /// <param name="ifcTreeItem"></param>
        private IFCItem FindIFCItem(IFCItem ifcParent, IFCTreeItem ifcTreeItem)
        {
            if (ifcParent == null)
            {
                return(null);
            }

            IFCItem ifcIterator = ifcParent;

            while (ifcIterator != null)
            {
                if (ifcIterator.ifcID == ifcTreeItem.instance)
                {
                    return(ifcIterator);
                }

                IFCItem ifcItem = FindIFCItem(ifcIterator.child, ifcTreeItem);
                if (ifcItem != null)
                {
                    return(ifcItem);
                }

                ifcIterator = ifcIterator.next;
            }

            return(FindIFCItem(ifcParent.child, ifcTreeItem));
        }
Exemple #3
0
        /// <summary>
        /// - Generates IFCProject-related items
        /// - Generates Not-referenced-in-structure items
        /// - Generates Header info
        /// - Generates check box per items
        /// </summary>
        public void BuildTree(ViewController ifcViewer, IntPtr ifcModel, IFCItem ifcRoot, TreeView treeControl)
        {
            treeControl.Items.Clear();

            if (ifcViewer == null)
            {
                throw new ArgumentException("The viewer is null.");
            }

            if (ifcModel == IntPtr.Zero)
            {
                throw new ArgumentException("Invalid model.");
            }

            if (ifcRoot == null)
            {
                throw new ArgumentException("The root is null.");
            }

            if (treeControl == null)
            {
                throw new ArgumentException("The tree control is null.");
            }

            _viewController = ifcViewer;
            _ifcModel       = ifcModel;
            _ifcRoot        = ifcRoot;
            _treeControl    = treeControl;

            _dicCheckedElements.Clear();

            CreateHeaderTreeItems();
            CreateProjectTreeItems();
            CreateNotReferencedTreeItems();
        }
Exemple #4
0
 public void SelectItem(IFCItem ifcItem)
 {
     if (ifcItem != null && ifcItem.Mesh3d != null)
     {
         OnModelSelected(ifcItem.Mesh3d);
     }
     this.Redraw();
 }
Exemple #5
0
        private void GenerateWireFrameGeometry(IntPtr ifcModel, IFCItem ifcItem)
        {
            if (ifcItem.ifcID != IntPtr.Zero)
            {
                IntPtr noVertices = IntPtr.Zero, noIndices = IntPtr.Zero;
                _ifcEngine.InitializeModellingInstance(ifcModel, ref noVertices, ref noIndices, 0, ifcItem.ifcID);

                if (noVertices != IntPtr.Zero && noIndices != IntPtr.Zero)
                {
                    ifcItem.noVerticesForWireFrame = noVertices.ToInt32();
                    ifcItem.verticesForWireFrame   = new float[3 * noVertices.ToInt32()];
                    ifcItem.indicesForWireFrame    = new int[noIndices.ToInt32()];

                    float[] pVertices = new float[noVertices.ToInt32() * 3];

                    _ifcEngine.FinalizeModelling(ifcModel, pVertices, ifcItem.indicesForWireFrame, IntPtr.Zero);

                    int i = 0;
                    while (i < noVertices.ToInt32())
                    {
                        ifcItem.verticesForWireFrame[3 * i + 0] = pVertices[3 * i + 0];
                        ifcItem.verticesForWireFrame[3 * i + 1] = pVertices[3 * i + 1];
                        ifcItem.verticesForWireFrame[3 * i + 2] = pVertices[3 * i + 2];

                        i++;
                    }
                    ;

                    ifcItem.noPrimitivesForWireFrame     = 0;
                    ifcItem.indicesForWireFrameLineParts = new int[2 * noIndices.ToInt32()];

                    int faceCnt = _ifcEngine.GetConceptualFaceCount(ifcItem.ifcID).ToInt32();

                    for (int j = 0; j < faceCnt; j++)
                    {
                        IntPtr startIndexFacesPolygons = IntPtr.Zero, noIndicesFacesPolygons = IntPtr.Zero, nonValue = IntPtr.Zero, nonValue1 = IntPtr.Zero, nonValue2 = IntPtr.Zero;
                        _ifcEngine.GetConceptualFaceEx(ifcItem.ifcID, new IntPtr(j), ref nonValue, ref nonValue, ref nonValue, ref nonValue, ref nonValue, ref nonValue1, ref startIndexFacesPolygons, ref noIndicesFacesPolygons, ref nonValue2, ref nonValue2);
                        i = 0;
                        int lastItem = -1;
                        while (i < noIndicesFacesPolygons.ToInt32())
                        {
                            if (lastItem >= 0 && ifcItem.indicesForWireFrame[startIndexFacesPolygons.ToInt32() + i] >= 0)
                            {
                                ifcItem.indicesForWireFrameLineParts[2 * ifcItem.noPrimitivesForWireFrame + 0] = lastItem;
                                ifcItem.indicesForWireFrameLineParts[2 * ifcItem.noPrimitivesForWireFrame + 1] = ifcItem.indicesForWireFrame[startIndexFacesPolygons.ToInt32() + i];
                                ifcItem.noPrimitivesForWireFrame++;
                            }
                            lastItem = ifcItem.indicesForWireFrame[startIndexFacesPolygons.ToInt32() + i];
                            i++;
                        }
                    }
                }
            }
        }
Exemple #6
0
        private void CreateWireFrameModels(IFCItem item, Vector3 center)
        {
            while (item != null)
            {
                if (item.ifcID != IntPtr.Zero && item.noVerticesForWireFrame != 0 && item.noPrimitivesForWireFrame != 0)
                {
                    var geo = new LineGeometry3D();
                    geo.Positions = new Vector3Collection();
                    geo.Indices   = new IntCollection();
                    var points = new Vector3Collection();
                    if (item.verticesForWireFrame != null)
                    {
                        for (int i = 0; i < item.noVerticesForWireFrame; i++)
                        {
                            points.Add(new Vector3((item.verticesForWireFrame[3 * i + 0] - center.X), (item.verticesForWireFrame[3 * i + 1] - center.Y), (item.verticesForWireFrame[3 * i + 2] - center.Z)));
                            geo.Positions.Add(new Vector3((item.verticesForWireFrame[3 * i + 0] - center.X), (item.verticesForWireFrame[3 * i + 1] - center.Y), (item.verticesForWireFrame[3 * i + 2] - center.Z)));
                        }
                    }

                    if (item.indicesForWireFrameLineParts != null)
                    {
                        for (int i = 0; i < item.noPrimitivesForWireFrame; i++)
                        {
                            var idx = item.indicesForWireFrameLineParts[2 * i + 0];
                            geo.Indices.Add(idx);
                            idx = item.indicesForWireFrameLineParts[2 * i + 1];
                            geo.Indices.Add(idx);
                        }
                    }
                    else
                    {
                        for (int i = 0, count = points.Count; i < count; i++)
                        {
                            geo.Indices.Add(i);
                            geo.Indices.Add((i + 1) % count);
                        }
                    }

                    LineGeometryModel3D line = new LineGeometryModel3D();
                    line.Geometry  = geo;
                    line.Color     = _defaultLineColor;
                    line.Thickness = 0.5;
                    item.Wireframe = line;

                    line.Tag = item.ifcType + ":" + item.ifcID;
                    model.Add(line);
                }

                CreateFaceModels(item.child, center);
                item = item.next;
            }
        }
Exemple #7
0
 public void Reset()
 {
     model.Clear();
     _meshToIfcItems.Clear();
     _hoverIfcItem    = null;
     _selectedIfcItem = null;
     _minCorner       = new float[3] {
         float.MaxValue, float.MaxValue, float.MaxValue
     };
     _maxCorner = new float[3] {
         float.MinValue, float.MinValue, float.MinValue
     };
 }
Exemple #8
0
        public bool OpenIFCFile(string ifcFilePath)
        {
            _rootIfcItem = null;
            Reset();

            if (ParseIfcFile(ifcFilePath) == true)
            {
                InitModel();
                Redraw();
                return(true);
            }

            return(false);
        }
Exemple #9
0
        void GenerateGeometry(IntPtr ifcModel, IFCItem ifcItem, ref int a)
        {
            while (ifcItem != null)
            {
                // Generate WireFrames Geometry
                IfcEngine.Setting setting = IfcEngine.Setting.Default;
                IfcEngine.Mask    mask    = IfcEngine.Mask.Default;
                mask |= IfcEngine.Mask.DoublePrecision; //    PRECISION (32/64 bit)
                mask |= IfcEngine.Mask.UseIndex64;      //	   INDEX ARRAY (32/64 bit)
                mask |= IfcEngine.Mask.GenNormals;      //    NORMALS
                mask |= IfcEngine.Mask.GenTriangles;    //    TRIANGLES
                mask |= IfcEngine.Mask.GenWireFrame;    //    WIREFRAME


                //                if (IntPtr.Size == 8) {
                //                    setting |= IfcEngine.Setting.UseIndex64; // 64 BIT INDEX ARRAY (Int64)
                //                }

                setting |= IfcEngine.Setting.GenWireframe; //    WIREFRAME ON


                _ifcEngine.SetFormat(ifcModel, setting, mask);

                GenerateWireFrameGeometry(ifcModel, ifcItem);

                // Generate Faces Geometry
                setting = IfcEngine.Setting.Default;

                //                if (IntPtr.Size == 8) {
                //                    setting |= IfcEngine.Setting.UseIndex64; //    64 BIT INDEX ARRAY (Int64)
                //                }

                setting |= IfcEngine.Setting.GenNormals;   //    NORMALS ON
                setting |= IfcEngine.Setting.GenTriangles; //    TRIANGLES ON

                _ifcEngine.SetFormat(ifcModel, setting, mask);

                GenerateFacesGeometry(ifcModel, ifcItem);

                _ifcEngine.CleanMemory(ifcModel);

                GenerateGeometry(ifcModel, ifcItem.child, ref a);
                ifcItem = ifcItem.next;
            }
        }
Exemple #10
0
        private void OnModelHovered(Model3D model)
        {
            if (_hoverIfcItem != null)
            {
                FillMeshByIfcColor(_hoverIfcItem);
                _hoverIfcItem = null;
            }
            if (model != null)
            {
                var mesh = (model as MeshGeometryModel3D);
                if (mesh != null && _meshToIfcItems.ContainsKey(mesh))
                {
                    mesh.Material = _hoverMaterial;
                    _hoverIfcItem = _meshToIfcItems[mesh];
                }
            }

            Redraw();
        }
Exemple #11
0
        /// <summary>
        /// Helper
        /// </summary>
        /// <param name="ifcTreeItem"></param>
        private void FindNonReferencedIFCItems(IFCItem ifcParent, TreeViewItem tnNotReferenced)
        {
            if (ifcParent == null)
            {
                return;
            }

            IFCItem ifcIterator = ifcParent;

            while (ifcIterator != null)
            {
                if ((ifcIterator.ifcTreeItem == null) && (ifcIterator.ifcID != IntPtr.Zero))
                {
                    string strItemText = "'" + (string.IsNullOrEmpty(ifcIterator.name) ? "<name>" : ifcIterator.name) +
                                         "' = '" + (string.IsNullOrEmpty(ifcIterator.description) ? "<description>" : ifcIterator.description) +
                                         "' (" + (string.IsNullOrEmpty(ifcIterator.ifcType) ? ifcIterator.globalID : ifcIterator.ifcType) + ")";

                    IFCTreeItem ifcTreeItem = new IFCTreeItem();
                    ifcTreeItem.instance = ifcIterator.ifcID;
                    ifcTreeItem.treeNode = new TreeViewItem()
                    {
                        Header = strItemText
                    };
                    tnNotReferenced.Items.Add(ifcTreeItem.treeNode);
                    ifcTreeItem.ifcItem      = FindIFCItem(_ifcRoot, ifcTreeItem);
                    ifcIterator.ifcTreeItem  = ifcTreeItem;
                    ifcTreeItem.treeNode.Tag = ifcTreeItem;

                    if (ifcTreeItem.ifcItem != null)
                    {
                        ifcTreeItem.ifcItem.ifcTreeItem = ifcTreeItem;
                    }
                }

                FindNonReferencedIFCItems(ifcIterator.child, tnNotReferenced);

                ifcIterator = ifcIterator.next;
            }

            FindNonReferencedIFCItems(ifcParent.child, tnNotReferenced);
        }
Exemple #12
0
        private void GenerateFacesGeometry(IntPtr ifcModel, IFCItem ifcItem)
        {
            if (ifcItem.ifcID != IntPtr.Zero)
            {
                IntPtr noVertices = IntPtr.Zero, noIndices = IntPtr.Zero;
                _ifcEngine.InitializeModellingInstance(ifcModel, ref noVertices, ref noIndices, 0, ifcItem.ifcID);

                if (noVertices != IntPtr.Zero && noIndices != IntPtr.Zero)
                {
                    ifcItem.noVerticesForFaces   = noVertices.ToInt32();
                    ifcItem.noPrimitivesForFaces = noIndices.ToInt32() / 3;
                    ifcItem.verticesForFaces     = new float[6 * noVertices.ToInt32()];
                    ifcItem.indicesForFaces      = new int[noIndices.ToInt32()];

                    float[] pVertices = new float[noVertices.ToInt32() * 6];

                    _ifcEngine.FinalizeModelling(ifcModel, pVertices, ifcItem.indicesForFaces, IntPtr.Zero);

                    int i = 0;
                    while (i < noVertices.ToInt32())
                    {
                        ifcItem.verticesForFaces[6 * i + 0] = pVertices[6 * i + 0];
                        ifcItem.verticesForFaces[6 * i + 1] = pVertices[6 * i + 1];
                        ifcItem.verticesForFaces[6 * i + 2] = pVertices[6 * i + 2];

                        ifcItem.verticesForFaces[6 * i + 3] = pVertices[6 * i + 3];
                        ifcItem.verticesForFaces[6 * i + 4] = pVertices[6 * i + 4];
                        ifcItem.verticesForFaces[6 * i + 5] = pVertices[6 * i + 5];

                        for (int j = 0; j < 3; j++)
                        {
                            _minCorner[j] = Math.Min(_minCorner[j], pVertices[6 * i + j]);
                            _maxCorner[j] = Math.Max(_maxCorner[j], pVertices[6 * i + j]);
                        }

                        i++;
                    }
                }
            }
        }
Exemple #13
0
 private void FillMeshByIfcColor(IFCItem item)
 {
     if (item.Mesh3d != null)
     {
         if (item.ifcTreeItem.ifcColor != null)
         {
             var ifcColor = item.ifcTreeItem.ifcColor;
             var color    = System.Windows.Media.Color.FromArgb((byte)(255 - ifcColor.A * 255), (byte)(ifcColor.R * 255), (byte)(ifcColor.G * 255), (byte)(ifcColor.B * 255));
             item.Mesh3d.Material = new PhongMaterial()
             {
                 AmbientColor    = Colors.Black.ToColor4(),
                 DiffuseColor    = Colors.Black.ToColor4(),
                 EmissiveColor   = color.ToColor4(),
                 ReflectiveColor = Colors.Black.ToColor4(),
                 SpecularColor   = color.ToColor4(),
             };
         }
         else
         {
             item.Mesh3d.Material = _defaultMaterial;
         }
     }
 }
Exemple #14
0
        private void OnModelSelected(Model3D model)
        {
            if (_selectedIfcItem != null)
            {
                _selectedIfcItem.ifcTreeItem.treeNode.IsSelected = false;
                FillMeshByIfcColor(_selectedIfcItem);
                _selectedIfcItem = null;
            }

            if (model != null)
            {
                var mesh = (model as MeshGeometryModel3D);
                if (mesh != null && _meshToIfcItems.ContainsKey(mesh))
                {
                    mesh.Material    = _selectMaterial;
                    _selectedIfcItem = _meshToIfcItems[mesh];
                    _selectedIfcItem.ifcTreeItem.treeNode.IsSelected = true;
                    _selectedIfcItem.ifcTreeItem.treeNode.Focus();
                    //                    _selectedIfcItem.ifcTreeItem.treeNode.ExpandSubtree();
                }
            }

            Redraw();
        }
Exemple #15
0
        public void CreateItem(IFCItem parent, IntPtr ifcID, string ifcType, string globalID, string name, string desc)
        {
            this.parent      = parent;
            this.next        = null;
            this.child       = null;
            this.globalID    = globalID;
            this.ifcID       = ifcID;
            this.ifcType     = ifcType;
            this.description = desc;
            this.name        = name;

            if (parent != null)
            {
                if (parent.child == null)
                {
                    parent.child = this;
                }
                else
                {
                    IFCItem NextChild = parent;

                    while (true)
                    {
                        if (NextChild.next == null)
                        {
                            NextChild.next = this;
                            break;
                        }
                        else
                        {
                            NextChild = NextChild.next;
                        }
                    }
                }
            }
        }
        private void RetrieveObjects(IntPtr ifcModel, string sObjectSPFFName, string ObjectDisplayName)
        {
            IntPtr ifcObjectInstances = _ifcEngine.GetEntityExtent(ifcModel, ObjectDisplayName),
                noIfcObjectIntances = _ifcEngine.GetMemberCount(ifcObjectInstances);

            if (noIfcObjectIntances != IntPtr.Zero) {
                IFCItem NewItem = null;
                if (_rootIfcItem == null) {
                    _rootIfcItem = new IFCItem();
                    _rootIfcItem.CreateItem(null, IntPtr.Zero, "", ObjectDisplayName, "", "");

                    NewItem = _rootIfcItem;
                } else {
                    IFCItem LastItem = _rootIfcItem;
                    while (LastItem != null) {
                        if (LastItem.next == null) {
                            LastItem.next = new IFCItem();
                            LastItem.next.CreateItem(null, IntPtr.Zero, "", ObjectDisplayName, "", "");

                            NewItem = LastItem.next;

                            break;
                        } else
                            LastItem = LastItem.next;
                    };
                }

                for (int i = 0; i < noIfcObjectIntances.ToInt32(); ++i) {
                    IntPtr ifcObjectIns = IntPtr.Zero;
                    _ifcEngine.GetAggregationElement(ifcObjectInstances, i, IfcEngine.SdaiType.Instance, out ifcObjectIns);

                    IntPtr value = IntPtr.Zero;
                    _ifcEngine.GetAttribute(ifcObjectIns, "GlobalId", IfcEngine.SdaiType.Unicode, out value);

                    string globalID = Marshal.PtrToStringUni((IntPtr)value);

                    value = IntPtr.Zero;
                    _ifcEngine.GetAttribute(ifcObjectIns, "Name", IfcEngine.SdaiType.Unicode, out value);

                    string name = Marshal.PtrToStringUni((IntPtr)value);

                    value = IntPtr.Zero;
                    _ifcEngine.GetAttribute(ifcObjectIns, "Description", IfcEngine.SdaiType.Unicode, out value);

                    string description = Marshal.PtrToStringUni((IntPtr)value);

                    IFCItem subItem = new IFCItem();
                    subItem.CreateItem(NewItem, ifcObjectIns, ObjectDisplayName, globalID, name, description);
                }
            }
        }
        private void OnModelSelected(Model3D model)
        {
            if (_selectedIfcItem != null) {
                _selectedIfcItem.ifcTreeItem.treeNode.IsSelected = false;
                FillMeshByIfcColor(_selectedIfcItem);
                _selectedIfcItem = null;
            }

            if (model != null) {
                var mesh = (model as MeshGeometryModel3D);
                if (mesh != null && _meshToIfcItems.ContainsKey(mesh)) {
                    mesh.Material = _selectMaterial;
                    _selectedIfcItem = _meshToIfcItems[mesh];
                    _selectedIfcItem.ifcTreeItem.treeNode.IsSelected = true;
                    _selectedIfcItem.ifcTreeItem.treeNode.Focus();
                    //                    _selectedIfcItem.ifcTreeItem.treeNode.ExpandSubtree();
                }
            }

            Redraw();
        }
        private void OnModelHovered(Model3D model)
        {
            if (_hoverIfcItem != null) {
                FillMeshByIfcColor(_hoverIfcItem);
                _hoverIfcItem = null;
            }
            if (model != null) {
                var mesh = (model as MeshGeometryModel3D);
                if (mesh != null && _meshToIfcItems.ContainsKey(mesh)) {
                    mesh.Material = _hoverMaterial;
                    _hoverIfcItem = _meshToIfcItems[mesh];
                }
            }

            Redraw();
        }
        private void GenerateWireFrameGeometry(IntPtr ifcModel, IFCItem ifcItem)
        {
            if (ifcItem.ifcID != IntPtr.Zero) {
                IntPtr noVertices = IntPtr.Zero, noIndices = IntPtr.Zero;
                _ifcEngine.InitializeModellingInstance(ifcModel, ref noVertices, ref noIndices, 0, ifcItem.ifcID);

                if (noVertices != IntPtr.Zero && noIndices != IntPtr.Zero) {
                    ifcItem.noVerticesForWireFrame = noVertices.ToInt32();
                    ifcItem.verticesForWireFrame = new float[3 * noVertices.ToInt32()];
                    ifcItem.indicesForWireFrame = new int[noIndices.ToInt32()];

                    float[] pVertices = new float[noVertices.ToInt32() * 3];

                    _ifcEngine.FinalizeModelling(ifcModel, pVertices, ifcItem.indicesForWireFrame, IntPtr.Zero);

                    int i = 0;
                    while (i < noVertices.ToInt32()) {
                        ifcItem.verticesForWireFrame[3 * i + 0] = pVertices[3 * i + 0];
                        ifcItem.verticesForWireFrame[3 * i + 1] = pVertices[3 * i + 1];
                        ifcItem.verticesForWireFrame[3 * i + 2] = pVertices[3 * i + 2];

                        i++;
                    };

                    ifcItem.noPrimitivesForWireFrame = 0;
                    ifcItem.indicesForWireFrameLineParts = new int[2 * noIndices.ToInt32()];

                    int faceCnt = _ifcEngine.GetConceptualFaceCount(ifcItem.ifcID).ToInt32();

                    for (int j = 0; j < faceCnt; j++) {
                        IntPtr startIndexFacesPolygons = IntPtr.Zero, noIndicesFacesPolygons = IntPtr.Zero, nonValue = IntPtr.Zero, nonValue1 = IntPtr.Zero, nonValue2 = IntPtr.Zero;
                        _ifcEngine.GetConceptualFaceEx(ifcItem.ifcID, new IntPtr(j), ref nonValue, ref nonValue, ref nonValue, ref nonValue, ref nonValue, ref nonValue1, ref startIndexFacesPolygons, ref noIndicesFacesPolygons, ref nonValue2, ref nonValue2);
                        i = 0;
                        int lastItem = -1;
                        while (i < noIndicesFacesPolygons.ToInt32()) {
                            if (lastItem >= 0 && ifcItem.indicesForWireFrame[startIndexFacesPolygons.ToInt32() + i] >= 0) {
                                ifcItem.indicesForWireFrameLineParts[2 * ifcItem.noPrimitivesForWireFrame + 0] = lastItem;
                                ifcItem.indicesForWireFrameLineParts[2 * ifcItem.noPrimitivesForWireFrame + 1] = ifcItem.indicesForWireFrame[startIndexFacesPolygons.ToInt32() + i];
                                ifcItem.noPrimitivesForWireFrame++;
                            }
                            lastItem = ifcItem.indicesForWireFrame[startIndexFacesPolygons.ToInt32() + i];
                            i++;
                        }
                    }
                }
            }
        }
        void GenerateGeometry(IntPtr ifcModel, IFCItem ifcItem, ref int a)
        {
            while (ifcItem != null) {
                // Generate WireFrames Geometry
                IfcEngine.Setting setting = IfcEngine.Setting.Default;
                IfcEngine.Mask mask = IfcEngine.Mask.Default;
                mask |= IfcEngine.Mask.DoublePrecision; //    PRECISION (32/64 bit)
                mask |= IfcEngine.Mask.UseIndex64; //	   INDEX ARRAY (32/64 bit)
                mask |= IfcEngine.Mask.GenNormals; //    NORMALS
                mask |= IfcEngine.Mask.GenTriangles; //    TRIANGLES
                mask |= IfcEngine.Mask.GenWireFrame; //    WIREFRAME

                //                if (IntPtr.Size == 8) {
                //                    setting |= IfcEngine.Setting.UseIndex64; // 64 BIT INDEX ARRAY (Int64)
                //                }

                setting |= IfcEngine.Setting.GenWireframe; //    WIREFRAME ON

                _ifcEngine.SetFormat(ifcModel, setting, mask);

                GenerateWireFrameGeometry(ifcModel, ifcItem);

                // Generate Faces Geometry
                setting = IfcEngine.Setting.Default;

                //                if (IntPtr.Size == 8) {
                //                    setting |= IfcEngine.Setting.UseIndex64; //    64 BIT INDEX ARRAY (Int64)
                //                }

                setting |= IfcEngine.Setting.GenNormals; //    NORMALS ON
                setting |= IfcEngine.Setting.GenTriangles; //    TRIANGLES ON

                _ifcEngine.SetFormat(ifcModel, setting, mask);

                GenerateFacesGeometry(ifcModel, ifcItem);

                _ifcEngine.CleanMemory(ifcModel);

                GenerateGeometry(ifcModel, ifcItem.child, ref a);
                ifcItem = ifcItem.next;
            }
        }
        private void GenerateFacesGeometry(IntPtr ifcModel, IFCItem ifcItem)
        {
            if (ifcItem.ifcID != IntPtr.Zero) {
                IntPtr noVertices = IntPtr.Zero, noIndices = IntPtr.Zero;
                _ifcEngine.InitializeModellingInstance(ifcModel, ref noVertices, ref noIndices, 0, ifcItem.ifcID);

                if (noVertices != IntPtr.Zero && noIndices != IntPtr.Zero) {
                    ifcItem.noVerticesForFaces = noVertices.ToInt32();
                    ifcItem.noPrimitivesForFaces = noIndices.ToInt32() / 3;
                    ifcItem.verticesForFaces = new float[6 * noVertices.ToInt32()];
                    ifcItem.indicesForFaces = new int[noIndices.ToInt32()];

                    float[] pVertices = new float[noVertices.ToInt32() * 6];

                    _ifcEngine.FinalizeModelling(ifcModel, pVertices, ifcItem.indicesForFaces, IntPtr.Zero);

                    int i = 0;
                    while (i < noVertices.ToInt32()) {
                        ifcItem.verticesForFaces[6 * i + 0] = pVertices[6 * i + 0];
                        ifcItem.verticesForFaces[6 * i + 1] = pVertices[6 * i + 1];
                        ifcItem.verticesForFaces[6 * i + 2] = pVertices[6 * i + 2];

                        ifcItem.verticesForFaces[6 * i + 3] = pVertices[6 * i + 3];
                        ifcItem.verticesForFaces[6 * i + 4] = pVertices[6 * i + 4];
                        ifcItem.verticesForFaces[6 * i + 5] = pVertices[6 * i + 5];

                        for (int j = 0; j < 3; j++) {
                            _minCorner[j] = Math.Min(_minCorner[j], pVertices[6 * i + j]);
                            _maxCorner[j] = Math.Max(_maxCorner[j], pVertices[6 * i + j]);
                        }

                        i++;
                    }
                }
            }
        }
Exemple #22
0
        /// <summary>
        /// Helper
        /// </summary>
        /// <param name="ifcTreeItem"></param>
        private IFCItem FindIFCItem(IFCItem ifcParent, IFCTreeItem ifcTreeItem)
        {
            if (ifcParent == null) {
                return null;
            }

            IFCItem ifcIterator = ifcParent;
            while (ifcIterator != null) {
                if (ifcIterator.ifcID == ifcTreeItem.instance) {
                    return ifcIterator;
                }

                IFCItem ifcItem = FindIFCItem(ifcIterator.child, ifcTreeItem);
                if (ifcItem != null) {
                    return ifcItem;
                }

                ifcIterator = ifcIterator.next;
            }

            return FindIFCItem(ifcParent.child, ifcTreeItem);
        }
        private void CreateWireFrameModels(IFCItem item, Vector3 center)
        {
            while (item != null) {
                if (item.ifcID != IntPtr.Zero && item.noVerticesForWireFrame != 0 && item.noPrimitivesForWireFrame != 0) {
                    var geo = new LineGeometry3D();
                    geo.Positions=new Vector3Collection();
                    geo.Indices=new IntCollection();
                    var points = new Vector3Collection();
                    if (item.verticesForWireFrame != null) {
                        for (int i = 0; i < item.noVerticesForWireFrame; i++) {
                            points.Add(new Vector3((item.verticesForWireFrame[3 * i + 0] - center.X), (item.verticesForWireFrame[3 * i + 1] - center.Y), (item.verticesForWireFrame[3 * i + 2] - center.Z)));
                            geo.Positions.Add(new Vector3((item.verticesForWireFrame[3 * i + 0] - center.X), (item.verticesForWireFrame[3 * i + 1] - center.Y), (item.verticesForWireFrame[3 * i + 2] - center.Z)));
                        }
                    }

                    if (item.indicesForWireFrameLineParts != null) {
                        for (int i = 0; i < item.noPrimitivesForWireFrame; i++) {
                            var idx = item.indicesForWireFrameLineParts[2 * i + 0];
                            geo.Indices.Add(idx);
                            idx = item.indicesForWireFrameLineParts[2 * i + 1];
                            geo.Indices.Add(idx);
                        }
                    } else {
                        for (int i = 0, count = points.Count; i < count; i++) {
                            geo.Indices.Add(i);
                            geo.Indices.Add((i + 1) % count);
                        }
                    }

                    LineGeometryModel3D line = new LineGeometryModel3D();
                    line.Geometry = geo;
                    line.Color = _defaultLineColor;
                    line.Thickness = 0.5;
                    item.Wireframe = line;

                    line.Tag = item.ifcType + ":" + item.ifcID;
                    model.Add(line);
                }

                CreateFaceModels(item.child, center);
                item = item.next;
            }
        }
 public void Reset()
 {
     model.Clear();
     _meshToIfcItems.Clear();
     _hoverIfcItem = null;
     _selectedIfcItem = null;
     _minCorner = new float[3] { float.MaxValue, float.MaxValue, float.MaxValue };
     _maxCorner = new float[3] { float.MinValue, float.MinValue, float.MinValue };
 }
Exemple #25
0
        /// <summary>
        /// - Generates IFCProject-related items
        /// - Generates Not-referenced-in-structure items
        /// - Generates Header info
        /// - Generates check box per items
        /// </summary>
        public void BuildTree(ViewController ifcViewer, IntPtr ifcModel, IFCItem ifcRoot, TreeView treeControl)
        {
            treeControl.Items.Clear();

            if (ifcViewer == null) {
                throw new ArgumentException("The viewer is null.");
            }

            if (ifcModel == IntPtr.Zero) {
                throw new ArgumentException("Invalid model.");
            }

            if (ifcRoot == null) {
                throw new ArgumentException("The root is null.");
            }

            if (treeControl == null) {
                throw new ArgumentException("The tree control is null.");
            }

            _viewController = ifcViewer;
            _ifcModel = ifcModel;
            _ifcRoot = ifcRoot;
            _treeControl = treeControl;

            _dicCheckedElements.Clear();

            CreateHeaderTreeItems();
            CreateProjectTreeItems();
            CreateNotReferencedTreeItems();
        }
Exemple #26
0
        /// <summary>
        /// Helper
        /// </summary>
        /// <param name="ifcTreeItem"></param>
        private void FindNonReferencedIFCItems(IFCItem ifcParent, TreeViewItem tnNotReferenced)
        {
            if (ifcParent == null) {
                return;
            }

            IFCItem ifcIterator = ifcParent;
            while (ifcIterator != null) {
                if ((ifcIterator.ifcTreeItem == null) && (ifcIterator.ifcID != IntPtr.Zero)) {
                    string strItemText = "'" + (string.IsNullOrEmpty(ifcIterator.name) ? "<name>" : ifcIterator.name) +
                            "' = '" + (string.IsNullOrEmpty(ifcIterator.description) ? "<description>" : ifcIterator.description) +
                            "' (" + (string.IsNullOrEmpty(ifcIterator.ifcType) ? ifcIterator.globalID : ifcIterator.ifcType) + ")";

                    IFCTreeItem ifcTreeItem = new IFCTreeItem();
                    ifcTreeItem.instance = ifcIterator.ifcID;
                    ifcTreeItem.treeNode = new TreeViewItem() { Header = strItemText };
                    tnNotReferenced.Items.Add(ifcTreeItem.treeNode);
                    ifcTreeItem.ifcItem = FindIFCItem(_ifcRoot, ifcTreeItem);
                    ifcIterator.ifcTreeItem = ifcTreeItem;
                    ifcTreeItem.treeNode.Tag = ifcTreeItem;

                    if (ifcTreeItem.ifcItem != null) {
                        ifcTreeItem.ifcItem.ifcTreeItem = ifcTreeItem;
                    }
                }

                FindNonReferencedIFCItems(ifcIterator.child, tnNotReferenced);

                ifcIterator = ifcIterator.next;
            }

            FindNonReferencedIFCItems(ifcParent.child, tnNotReferenced);
        }
Exemple #27
0
        private void CreateFaceModels(IFCItem item, Vector3 center)
        {
            while (item != null)
            {
                if (item.ifcID != IntPtr.Zero && item.noVerticesForFaces != 0 && item.noPrimitivesForFaces != 0)
                {
                    var positions = new Vector3Collection();
                    var normals   = new Vector3Collection();
                    if (item.verticesForFaces != null)
                    {
                        for (int i = 0; i < item.noVerticesForFaces; i++)
                        {
                            var point  = new Vector3(item.verticesForFaces[6 * i + 0] - center.X, item.verticesForFaces[6 * i + 1] - center.Y, item.verticesForFaces[6 * i + 2] - center.Z);
                            var normal = new Vector3(item.verticesForFaces[6 * i + 3], item.verticesForFaces[6 * i + 4], item.verticesForFaces[6 * i + 5]);
                            positions.Add(point);
                            normals.Add(normal);
                        }

                        Debug.Assert(item.verticesForFaces.Length == item.noVerticesForFaces * 6);
                    }

                    var indices = new IntCollection();
                    if (item.indicesForFaces != null)
                    {
                        for (int i = 0; i < 3 * item.noPrimitivesForFaces; i++)
                        {
                            indices.Add(item.indicesForFaces[i]);
                        }
                    }

                    var meshGeometry = new MeshGeometry3D();
                    meshGeometry.Positions          = positions;
                    meshGeometry.Normals            = normals;
                    meshGeometry.Indices            = indices;
                    meshGeometry.TextureCoordinates = null;
                    meshGeometry.Colors             = null;
                    meshGeometry.Tangents           = null;
                    meshGeometry.BiTangents         = null;

                    MeshGeometryModel3D mesh = new MeshGeometryModel3D()
                    {
                        Geometry = meshGeometry
                    };
                    //                    var builder = new MeshBuilder(true, false);
                    //                    builder.Positions.AddRange(positions);
                    //                    builder.Normals.AddRange(normals);
                    //                    builder.TriangleIndices.AddRange(indices);
                    //                    MeshGeometryModel3D mesh = new MeshGeometryModel3D() { Geometry = builder.ToMeshGeometry3D() };
                    item.Mesh3d           = mesh;
                    _meshToIfcItems[mesh] = item;
                    //#if DEBUG
                    //                    OutputObj(item.ifcID.ToString(), meshGeometry);
                    //#endif
                    FillMeshByIfcColor(item);

                    mesh.Tag = item.ifcType + ":" + item.ifcID;
                    model.Add(mesh);
                }

                CreateFaceModels(item.child, center);
                item = item.next;
            }
        }
 private void FillMeshByIfcColor(IFCItem item)
 {
     if (item.Mesh3d != null) {
         if (item.ifcTreeItem.ifcColor != null) {
             var ifcColor = item.ifcTreeItem.ifcColor;
             var color = System.Windows.Media.Color.FromArgb((byte)(255 - ifcColor.A * 255), (byte)(ifcColor.R * 255), (byte)(ifcColor.G * 255), (byte)(ifcColor.B * 255));
             item.Mesh3d.Material = new PhongMaterial() {
                 AmbientColor = Colors.Black.ToColor4(),
                 DiffuseColor = Colors.Black.ToColor4(),
                 EmissiveColor = color.ToColor4(),
                 ReflectiveColor = Colors.Black.ToColor4(),
                 SpecularColor = color.ToColor4(),
             };
         } else {
             item.Mesh3d.Material = _defaultMaterial;
         }
     }
 }
 public void SelectItem(IFCItem ifcItem)
 {
     if (ifcItem != null && ifcItem.Mesh3d != null) {
         OnModelSelected(ifcItem.Mesh3d);
     }
     this.Redraw();
 }
Exemple #30
0
        private void RetrieveObjects(IntPtr ifcModel, string sObjectSPFFName, string ObjectDisplayName)
        {
            IntPtr ifcObjectInstances  = _ifcEngine.GetEntityExtent(ifcModel, ObjectDisplayName),
                   noIfcObjectIntances = _ifcEngine.GetMemberCount(ifcObjectInstances);

            if (noIfcObjectIntances != IntPtr.Zero)
            {
                IFCItem NewItem = null;
                if (_rootIfcItem == null)
                {
                    _rootIfcItem = new IFCItem();
                    _rootIfcItem.CreateItem(null, IntPtr.Zero, "", ObjectDisplayName, "", "");

                    NewItem = _rootIfcItem;
                }
                else
                {
                    IFCItem LastItem = _rootIfcItem;
                    while (LastItem != null)
                    {
                        if (LastItem.next == null)
                        {
                            LastItem.next = new IFCItem();
                            LastItem.next.CreateItem(null, IntPtr.Zero, "", ObjectDisplayName, "", "");

                            NewItem = LastItem.next;

                            break;
                        }
                        else
                        {
                            LastItem = LastItem.next;
                        }
                    }
                    ;
                }


                for (int i = 0; i < noIfcObjectIntances.ToInt32(); ++i)
                {
                    IntPtr ifcObjectIns = IntPtr.Zero;
                    _ifcEngine.GetAggregationElement(ifcObjectInstances, i, IfcEngine.SdaiType.Instance, out ifcObjectIns);

                    IntPtr value = IntPtr.Zero;
                    _ifcEngine.GetAttribute(ifcObjectIns, "GlobalId", IfcEngine.SdaiType.Unicode, out value);

                    string globalID = Marshal.PtrToStringUni((IntPtr)value);

                    value = IntPtr.Zero;
                    _ifcEngine.GetAttribute(ifcObjectIns, "Name", IfcEngine.SdaiType.Unicode, out value);

                    string name = Marshal.PtrToStringUni((IntPtr)value);

                    value = IntPtr.Zero;
                    _ifcEngine.GetAttribute(ifcObjectIns, "Description", IfcEngine.SdaiType.Unicode, out value);

                    string description = Marshal.PtrToStringUni((IntPtr)value);

                    IFCItem subItem = new IFCItem();
                    subItem.CreateItem(NewItem, ifcObjectIns, ObjectDisplayName, globalID, name, description);
                }
            }
        }
        public bool OpenIFCFile(string ifcFilePath)
        {
            _rootIfcItem = null;
            Reset();

            if (ParseIfcFile(ifcFilePath) == true) {
                InitModel();
                Redraw();
                return true;
            }

            return false;
        }
        private void CreateFaceModels(IFCItem item, Vector3 center)
        {
            while (item != null) {
                if (item.ifcID != IntPtr.Zero && item.noVerticesForFaces != 0 && item.noPrimitivesForFaces != 0) {
                    var positions = new Vector3Collection();
                    var normals = new Vector3Collection();
                    if (item.verticesForFaces != null) {
                        for (int i = 0; i < item.noVerticesForFaces; i++) {
                            var point = new Vector3(item.verticesForFaces[6 * i + 0] - center.X, item.verticesForFaces[6 * i + 1] - center.Y, item.verticesForFaces[6 * i + 2] - center.Z);
                            var normal = new Vector3(item.verticesForFaces[6 * i + 3], item.verticesForFaces[6 * i + 4], item.verticesForFaces[6 * i + 5]);
                            positions.Add(point);
                            normals.Add(normal);
                        }

                        Debug.Assert(item.verticesForFaces.Length == item.noVerticesForFaces * 6);
                    }

                    var indices = new IntCollection();
                    if (item.indicesForFaces != null) {
                        for (int i = 0; i < 3 * item.noPrimitivesForFaces; i++) {
                            indices.Add(item.indicesForFaces[i]);
                        }
                    }

                    var meshGeometry = new MeshGeometry3D();
                    meshGeometry.Positions = positions;
                    meshGeometry.Normals = normals;
                    meshGeometry.Indices = indices;
                    meshGeometry.TextureCoordinates = null;
                    meshGeometry.Colors = null;
                    meshGeometry.Tangents = null;
                    meshGeometry.BiTangents = null;

                    MeshGeometryModel3D mesh = new MeshGeometryModel3D() { Geometry = meshGeometry };
                    //                    var builder = new MeshBuilder(true, false);
                    //                    builder.Positions.AddRange(positions);
                    //                    builder.Normals.AddRange(normals);
                    //                    builder.TriangleIndices.AddRange(indices);
                    //                    MeshGeometryModel3D mesh = new MeshGeometryModel3D() { Geometry = builder.ToMeshGeometry3D() };
                    item.Mesh3d = mesh;
                    _meshToIfcItems[mesh] = item;
                    //#if DEBUG
                    //                    OutputObj(item.ifcID.ToString(), meshGeometry);
                    //#endif
                    FillMeshByIfcColor(item);

                    mesh.Tag = item.ifcType + ":" + item.ifcID;
                    model.Add(mesh);
                }

                CreateFaceModels(item.child, center);
                item = item.next;
            }
        }