Example #1
0
        internal static List <Data> Run(Xbim.Ifc.IfcStore model)
        {
            // Specify elements
            List <Xbim.Ifc2x3.Interfaces.IIfcWall> allWalls =
                model.Instances.OfType <Xbim.Ifc2x3.Interfaces.IIfcWall>().ToList(); int a = allWalls.Count();

            List <Xbim.Ifc2x3.Interfaces.IIfcOpeningElement> allOpenigs =
                model.Instances.OfType <Xbim.Ifc2x3.Interfaces.IIfcOpeningElement>().ToList(); int b = allOpenigs.Count();

            List <Xbim.Ifc2x3.Interfaces.IIfcBeamType> allBeams =
                model.Instances.OfType <Xbim.Ifc2x3.Interfaces.IIfcBeamType>().ToList(); int c = allBeams.Count();

            List <Xbim.Ifc2x3.Interfaces.IIfcColumnType> allColumns =
                model.Instances.OfType <Xbim.Ifc2x3.Interfaces.IIfcColumnType>().ToList(); int d = allColumns.Count();

            List <Xbim.Ifc2x3.Interfaces.IIfcElement> ifcElements =
                model.Instances.OfType <Xbim.Ifc2x3.Interfaces.IIfcElement>().ToList(); int e = ifcElements.Count();


            // Extract geometry
            var context = new Xbim3DModelContext(model);

            context.CreateContext();
            var instances = context.ShapeInstances().ToList();
            IEnumerator <XbimShapeInstance> allShapeInstances = instances.GetEnumerator();

            List <Data> allData = new List <Data>();

            while (allShapeInstances.MoveNext())
            {
                // get data from shape instance
                XbimShapeInstance xbimShapeInstance        = allShapeInstances.Current;
                Xbim.Ifc2x3.Interfaces.IIfcElement element = ifcElements.FirstOrDefault(x => x.EntityLabel == xbimShapeInstance.IfcProductLabel);
                string name = element.Name;
                string id   = element.GlobalId;

                var ro          = xbimShapeInstance.Transformation;
                var translation = ro.Translation;
                var decompose   = ro.Decompose(out XbimVector3D scale, out XbimQuaternion rot, out XbimVector3D trans);

                Matrix <double> matrixData = DenseMatrix.OfArray(new double[, ] {
                    { ro.M11, ro.M12, ro.M13, ro.M14 },
                    { ro.M21, ro.M22, ro.M23, ro.M24 },
                    { ro.M31, ro.M32, ro.M33, ro.M34 },
                    { ro.OffsetX, ro.OffsetY, ro.OffsetZ, ro.M44 }
                });
                matrixData = matrixData.Transpose();
                Console.WriteLine(matrixData.ToString());
                XbimRect3D  rect = xbimShapeInstance.BoundingBox;
                XbimPoint3D Min  = rect.Min;
                XbimPoint3D Max  = rect.Max;
                Data        data = new Data
                                   (
                    name,
                    id,
                    new BoundingBox(new XYZ(Min.X, Min.Y, Min.Z), new XYZ(Max.X, Max.Y, Max.Z)),
                    new XYZ(translation.X, translation.Y, translation.Z),
                    matrixData
                                   );
                allData.Add(data);
            }

            return(allData);
        }
        public XbimReferencedModel(IIfcDocumentInformation documentInformation)
        {
            DocumentInformation = documentInformation;

            // for legacy purposes we should be able to load files from the name inside the document information
            // but the correct approach seems to be to have that data using the HasDocumentReferences property:
            // in the specs we read that
            // "The actual content of the document is not defined in IFC ; instead, it can be found following the reference given to IfcDocumentReference."
            //
            var searchPaths = new List <string>();

            if (documentInformation.Model is IfcStore)
            {
                var referencingStore = documentInformation.Model as IfcStore;
                var fi = new FileInfo(referencingStore.FileName);
                searchPaths.Add(fi.DirectoryName);
            }
            var headerFileName = documentInformation.Model?.Header?.FileName?.Name;

            if (Path.IsPathRooted(headerFileName))
            {
                searchPaths.Add(Path.GetDirectoryName(headerFileName));
            }

            // we will use the first valid document reference in a list that is evaluate as absolute or relative.
            //
            var candidates = DocumentInformation.HasDocumentReferences.Select(x => x.Location).ToList();

            candidates.Add(documentInformation.Name.ToString()); // this is for legacy in xbim federations

            string resourceReference = string.Empty;

            // evaluating absolute path
            foreach (var candidate in candidates)
            {
                var thisCandidate = candidate;
                // check if can be found as is
                if (File.Exists(thisCandidate))
                {
                    resourceReference = thisCandidate;
                    break;
                }
                // check if it can be relative
                if (!Path.IsPathRooted(candidate))
                {
                    foreach (var path in searchPaths)
                    {
                        thisCandidate = Path.Combine(
                            path, candidate
                            );
                        if (File.Exists(thisCandidate))
                        {
                            resourceReference = thisCandidate;
                            goto StopSearch;
                        }
                    }
                }
            }

StopSearch:
            if (string.IsNullOrEmpty(resourceReference))
            {
                throw new XbimException($"Reference model not found for IfcDocumentInformation #{documentInformation.EntityLabel}.");
            }
            try
            {
                _model = IfcStore.Open(resourceReference);
            }
            catch (Exception ex)
            {
                throw new XbimException("Error opening referenced model: " + resourceReference, ex);
            }
        }