/// <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.Nodes.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."); } Cursor.Current = Cursors.WaitCursor; _viewController = ifcViewer; _ifcModel = ifcModel; _ifcRoot = ifcRoot; _treeControl = treeControl; _dicCheckedElements.Clear(); CreateHeaderTreeItems(); CreateProjectTreeItems(); CreateNotReferencedTreeItems(); }
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; } } } } }
public void SelectItem(IFCItem ifcItem) { if (ifcItem != null && ifcItem.Mesh3d != null) { OnModelSelected(ifcItem.Mesh3d); } this.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++; } } } } }
public void Reset() { _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 }; }
private void CreateFaceModels(IFCItem item, Vector3D center) { while (item != null) { if (item.ifcID != IntPtr.Zero && item.noVerticesForFaces != 0 && item.noPrimitivesForFaces != 0) { var positions = new Point3DCollection(); var normals = new Vector3DCollection(); if (item.verticesForFaces != null) { for (int i = 0; i < item.noVerticesForFaces; i++) { var point = new Point3D(item.verticesForFaces[6 * i + 0] - center.X, item.verticesForFaces[6 * i + 1] - center.Y, item.verticesForFaces[6 * i + 2] - center.Z); var normal = new Vector3D(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 Int32Collection(); if (item.indicesForFaces != null) { for (int i = 0; i < 3 * item.noPrimitivesForFaces; i++) { indices.Add(item.indicesForFaces[i]); } } MeshGeometry3D meshGeometry = new MeshGeometry3D(); meshGeometry.Positions = positions; meshGeometry.Normals = normals; meshGeometry.TriangleIndices = indices; MeshGeometryVisual3D mesh = new MeshGeometryVisual3D(); mesh.MeshGeometry = meshGeometry; item.Mesh3d = mesh; _meshToIfcItems[mesh] = item; #if DEBUG OutputObj(item.ifcID.ToString(), meshGeometry); #endif FillMeshByIfcColor(item); hVp3D.Children.Add(mesh); } CreateFaceModels(item.child, center); item = item.next; } }
public bool OpenIFCFile(string ifcFilePath) { _rootIfcItem = null; Reset(); if (ParseIfcFile(ifcFilePath) == true) { InitModel(); Redraw(); return(true); } return(false); }
private void FillMeshByIfcColor(IFCItem item) { if (item.Mesh3d != null) { if (item.ifcTreeItem.ifcColor != null) { var ifcColor = item.ifcTreeItem.ifcColor; var color = Color.FromArgb((byte)(255 - ifcColor.A * 255), (byte)(ifcColor.R * 255), (byte)(ifcColor.G * 255), (byte)(ifcColor.B * 255)); item.Mesh3d.Fill = new SolidColorBrush(color); } else { item.Mesh3d.Fill = _defaultBrush; } } }
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 OnModelHovered(Visual3D model) { if (_hoverIfcItem != null) { FillMeshByIfcColor(_hoverIfcItem); _hoverIfcItem = null; } if (model != null) { var mesh = (model as MeshGeometryVisual3D); if (mesh != null && _meshToIfcItems.ContainsKey(mesh)) { mesh.Fill = _hoverBrush; _hoverIfcItem = _meshToIfcItems[mesh]; } } Redraw(); }
private void CreateWireFrameModels(IFCItem item, Vector3D center) { while (item != null) { if (item.ifcID != IntPtr.Zero && item.noVerticesForWireFrame != 0 && item.noPrimitivesForWireFrame != 0) { var points = new Point3DCollection(); Point3DCollection positions; if (item.verticesForWireFrame != null) { for (int i = 0; i < item.noVerticesForWireFrame; i++) { points.Add(new Point3D((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) { positions = new Point3DCollection(); for (int i = 0; i < item.noPrimitivesForWireFrame; i++) { var idx = item.indicesForWireFrameLineParts[2 * i + 0]; positions.Add(points[idx]); idx = item.indicesForWireFrameLineParts[2 * i + 1]; positions.Add(points[idx]); } } else { positions = points; } LinesVisual3D wireframe = new LinesVisual3D(); wireframe.Points = positions; wireframe.Color = _defaultLineColor; item.Wireframe = wireframe; hVp3D.Children.Add(wireframe); } CreateFaceModels(item.child, center); item = item.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++; } } } }
private void OnModelSelected(Visual3D model) { if (_selectedIfcItem != null) { FillMeshByIfcColor(_selectedIfcItem); _selectedIfcItem = null; } if (model != null) { var mesh = (model as MeshGeometryVisual3D); if (mesh != null && _meshToIfcItems.ContainsKey(mesh)) { mesh.Fill = _selectBrush; _selectedIfcItem = _meshToIfcItems[mesh]; _selectedIfcItem.ifcTreeItem.treeNode.TreeView.SelectedNode = _selectedIfcItem.ifcTreeItem.treeNode; _selectedIfcItem.ifcTreeItem.treeNode.TreeView.Focus(); //_selectedIfcItem.ifcTreeItem.treeNode.Expand(); _selectedIfcItem.ifcTreeItem.treeNode.EnsureVisible(); } } Redraw(); }
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 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++; } } } } }
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); } } }
/// <summary> /// Helper /// </summary> /// <param name="ifcItem"></param> public void OnSelectIFCElement(IFCItem ifcItem) { System.Diagnostics.Debug.Assert(ifcItem != null, "Internal error."); System.Diagnostics.Debug.Assert(ifcItem.ifcTreeItem != null, "Internal error."); System.Diagnostics.Debug.Assert(ifcItem.ifcTreeItem.treeNode != null, "Internal error."); _treeControl.SelectedNode = ifcItem.ifcTreeItem.treeNode; }
/// <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); }
/// <summary> /// Helper /// </summary> /// <param name="ifcTreeItem"></param> private void FindNonReferencedIFCItems(IFCItem ifcParent, TreeNode 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 = tnNotReferenced.Nodes.Add(strItemText); ifcTreeItem.ifcItem = FindIFCItem(_ifcRoot, ifcTreeItem); ifcIterator.ifcTreeItem = ifcTreeItem; ifcTreeItem.treeNode.Tag = ifcTreeItem; if (ifcTreeItem.ifcItem != null) { ifcTreeItem.ifcItem.ifcTreeItem = ifcTreeItem; ifcTreeItem.treeNode.ImageIndex = ifcTreeItem.treeNode.SelectedImageIndex = IMAGE_CHECKED; } else { ifcTreeItem.treeNode.ImageIndex = ifcTreeItem.treeNode.SelectedImageIndex = IMAGE_NOT_REFERENCED; } } FindNonReferencedIFCItems(ifcIterator.child, tnNotReferenced); ifcIterator = ifcIterator.next; } FindNonReferencedIFCItems(ifcParent.child, tnNotReferenced); }
public bool OpenIFCFile(string ifcFilePath) { _rootIfcItem = null; Reset(); if (ParseIfcFile(ifcFilePath) == true) { InitModel(); Redraw(); return true; } return false; }