Esempio n. 1
0
        private ProcessResult ProcessFile(string ifcFile, StreamWriter writer, ILogger <BatchProcessor> logger)
        {
            RemoveFiles(ifcFile);
            // using (var eventTrace = LoggerFactory.CreateEventTrace())
            {
                var result = new ProcessResult()
                {
                    Errors = -1
                };
                var watch = new Stopwatch();
                try
                {
                    watch.Start();
                    using (var model = ParseModelFile(ifcFile, Params.Caching, logger))
                    {
                        var parseTime    = watch.ElapsedMilliseconds;
                        var xbimFilename = BuildFileName(ifcFile, ".xbim");
                        var context      = new Xbim3DModelContext(model, logger: logger);
                        if (_params.MaxThreads > 0)
                        {
                            context.MaxThreads = _params.MaxThreads;
                        }
                        // context.CustomMeshingBehaviour = CustomMeshingBehaviour;
                        context.CreateContext();
                        //}
                        var geomTime = watch.ElapsedMilliseconds - parseTime;
                        //XbimSceneBuilder sb = new XbimSceneBuilder();
                        //string xbimSceneName = BuildFileName(ifcFile, ".xbimScene");
                        //sb.BuildGlobalScene(model, xbimSceneName);
                        // sceneTime = watch.ElapsedMilliseconds - geomTime;
                        var header = model.Header;
                        watch.Stop();
                        var ohs = model.Instances.OfType <IIfcOwnerHistory>().FirstOrDefault();
                        using (var geomReader = model.GeometryStore.BeginRead())
                        {
                            result = new ProcessResult
                            {
                                ParseDuration    = parseTime,
                                GeometryDuration = geomTime,
                                // SceneDuration = sceneTime,
                                FileName       = ifcFile.Remove(0, Params.TestFileRoot.Length).TrimStart('\\'),
                                Entities       = model.Instances.Count,
                                IfcSchema      = header.FileSchema.Schemas.FirstOrDefault(),
                                IfcDescription =
                                    string.Format("{0}, {1}", header.FileDescription.Description.FirstOrDefault(),
                                                  header.FileDescription.ImplementationLevel),
                                GeometryEntries     = geomReader.ShapeInstances.Count(),
                                IfcLength           = ReadFileLength(ifcFile),
                                XbimLength          = ReadFileLength(xbimFilename),
                                SceneLength         = 0,
                                IfcProductEntries   = model.Instances.OfType <IIfcProduct>().Count(),
                                IfcSolidGeometries  = model.Instances.OfType <IIfcSolidModel>().Count(),
                                IfcMappedGeometries = model.Instances.OfType <IIfcMappedItem>().Count(),
                                BooleanGeometries   = model.Instances.OfType <IIfcBooleanResult>().Count(),
                                BReps = model.Instances.OfType <IIfcFaceBasedSurfaceModel>().Count() +
                                        model.Instances.OfType <IIfcShellBasedSurfaceModel>().Count() + model.Instances
                                        .OfType <IIfcManifoldSolidBrep>().Count(),
                                Application = ohs == null ? "Unknown" : ohs.OwningApplication?.ApplicationFullName.ToString()
                            };
                        }

                        // Option to save breps of encountered classes by type or entityLabel for debugging purposes

                        if (_params.WriteBreps)
                        {
                            var path = Path.Combine(
                                Path.GetDirectoryName(ifcFile),
                                Path.GetFileName(ifcFile) + ".brep.unclassified");
                            IXbimGeometryEngine engine = new XbimGeometryEngine();
                            if (!Directory.Exists(path))
                            {
                                Directory.CreateDirectory(path);
                            }
                            IfcStore s = model as IfcStore;
                            if (s != null)
                            {
                                var ents = new List <IPersistEntity>();

                                var exportBrepByType = new string[]
                                {
                                    "IfcFacetedBrep",
                                    // IIfcGeometricRepresentationItem
                                    "IfcCsgSolid",
                                    "IfcExtrudedAreaSolid",
                                    "IfcExtrudedAreaSolidTapered",
                                    "IfcFixedReferenceSweptAreaSolid",
                                    "IfcRevolvedAreaSolid",
                                    "IfcRevolvedAreaSolidTapered",
                                    "IfcSurfaceCurveSweptAreaSolid",
                                    "IfcSectionedSolidHorizontal",
                                    "IfcSweptDiskSolid",
                                    "IfcSweptDiskSolidPolygonal",
                                    "IfcBooleanResult",
                                    "IfcBooleanClippingResult",
                                    // composing objects
                                    "IfcConnectedFaceSet"
                                };

                                // ADD Individual entities to extract brep here
                                // ents.Add(s.Instances[69512]);

                                foreach (var type in exportBrepByType)
                                {
                                    ents.AddRange(s.Instances.OfType(type, false));
                                }
                                foreach (var ent in ents)
                                {
                                    try
                                    {
                                        Xbim.Common.Geometry.IXbimGeometryObject created = null;
                                        if (ent is IIfcGeometricRepresentationItem igri)
                                        {
                                            created = engine.Create(igri);
                                        }
                                        if (ent is IIfcConnectedFaceSet icfs)
                                        {
                                            created = engine.CreateShell(icfs);
                                        }
                                        // IIfcConnectedFaceSet
                                        if (created != null)
                                        {
                                            var brep         = engine.ToBrep(created);
                                            var brepFileName = Path.Combine(path, $"{ent.EntityLabel}.{ent.GetType().Name}.brep");
                                            using (var tw = File.CreateText(brepFileName))
                                            {
                                                tw.WriteLine("DBRep_DrawableShape");
                                                tw.WriteLine(brep);
                                            }
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        Console.WriteLine($"Error writing brep {ent.EntityLabel}: {ex.Message}");
                                    }
                                }
                            }
                        }

                        if (_params.Caching)
                        {
                            IfcStore s = ((IfcStore)model);
                            if (s != null)
                            {
                                s.SaveAs(xbimFilename, Xbim.IO.StorageType.Xbim);
                                s.Close();
                            }
                        }
                    }
                }

                catch (Exception ex)
                {
                    logger.LogError(string.Format("Problem converting file: {0}", ifcFile), ex);
                    result.Failed           = true;
                    result.GeometryDuration = watch.ElapsedMilliseconds;
                }

                return(result);
            }
        }
Esempio n. 2
0
        private ProcessResult ProcessFile(string ifcFile)
        {
            RemoveFiles(ifcFile);
            long geomTime = -1;  long parseTime = -1;

            using (EventTrace eventTrace = LoggerFactory.CreateEventTrace())
            {
                ProcessResult result = new ProcessResult()
                {
                    Errors = -1
                };
                try
                {
                    Stopwatch watch = new Stopwatch();
                    watch.Start();
                    using (var model = ParseModelFile(ifcFile, Params.Caching))
                    {
                        parseTime = watch.ElapsedMilliseconds;
                        string xbimFilename = BuildFileName(ifcFile, ".xbim");
                        //add geometry
                        Xbim3DModelContext m3d = new Xbim3DModelContext(model);
                        try
                        {
                            m3d.CreateContext();
                        }
                        catch (Exception ex)
                        {
                            Logger.Error(String.Format("Error compiling geometry: {0} - {1}", ifcFile, ex.Message), ex);
                        }
                        geomTime = watch.ElapsedMilliseconds - parseTime;
                        IStepFileHeader header = model.Header;
                        watch.Stop();
                        var ohs = model.Instances.OfType <IIfcOwnerHistory>().FirstOrDefault();
                        result = new ProcessResult()
                        {
                            ParseDuration    = parseTime,
                            GeometryDuration = geomTime,
                            SceneDuration    = 0,
                            FileName         = ifcFile,
                            Entities         = model.Instances.Count,
                            IfcSchema        = header.FileSchema.Schemas.FirstOrDefault(),
                            IfcDescription   = String.Format("{0}, {1}", header.FileDescription.Description.FirstOrDefault(), header.FileDescription.ImplementationLevel),
                            //GeometryEntries = model.,
                            IfcLength           = ReadFileLength(ifcFile),
                            XbimLength          = ReadFileLength(xbimFilename),
                            SceneLength         = 0,
                            IfcProductEntries   = model.Instances.CountOf <IIfcProduct>(),
                            IfcSolidGeometries  = model.Instances.CountOf <IIfcSolidModel>(),
                            IfcMappedGeometries = model.Instances.CountOf <IIfcMappedItem>(),
                            BooleanGeometries   = model.Instances.CountOf <IIfcBooleanResult>(),
                            Application         = ohs == null ? "Unknown" : ohs.OwningApplication.ToString(),
                        };
                    }
                }

                catch (Exception ex)
                {
                    Logger.Error(String.Format("Problem converting file: {0}", ifcFile), ex);
                    result.Failed = true;
                }
                finally
                {
                    result.Errors = (from e in eventTrace.Events
                                     where (e.EventLevel == EventLevel.ERROR)
                                     select e).Count();
                    result.Warnings = (from e in eventTrace.Events
                                       where (e.EventLevel == EventLevel.WARN)
                                       select e).Count();
                    result.FileName = ifcFile;
                    if (eventTrace.Events.Count > 0)
                    {
                        CreateLogFile(ifcFile, eventTrace.Events);
                    }
                    //add last reports pass/fail and save report to report set
                    if (_lastReportSet != null)
                    {
                        result.LastTestFailed = _lastReportSet.Compare(result); //set last test pass/fail result
                    }
                    _thisReportSet.Add(result);
                }
                return(result);
            }
        }
Esempio n. 3
0
        private ProcessResult ProcessFile(string ifcFile, StreamWriter writer)
        {
            RemoveFiles(ifcFile);
            long geomTime = -1;  long parseTime = -1;

            using (EventTrace eventTrace = LoggerFactory.CreateEventTrace())
            {
                ProcessResult result = new ProcessResult()
                {
                    Errors = -1
                };
                try
                {
                    Stopwatch watch = new Stopwatch();
                    watch.Start();
                    using (var model = ParseModelFile(ifcFile, Params.Caching))
                    {
                        parseTime = watch.ElapsedMilliseconds;
                        string             xbimFilename = BuildFileName(ifcFile, ".xbim");
                        Xbim3DModelContext context      = new Xbim3DModelContext(model);
                        context.CreateContext();
                        //}
                        geomTime = watch.ElapsedMilliseconds - parseTime;
                        //XbimSceneBuilder sb = new XbimSceneBuilder();
                        //string xbimSceneName = BuildFileName(ifcFile, ".xbimScene");
                        //sb.BuildGlobalScene(model, xbimSceneName);
                        // sceneTime = watch.ElapsedMilliseconds - geomTime;
                        IStepFileHeader header = model.Header;
                        watch.Stop();
                        IIfcOwnerHistory ohs = model.Instances.OfType <IIfcOwnerHistory>().FirstOrDefault();
                        using (var geomReader = model.GeometryStore.BeginRead())
                        {
                            result = new ProcessResult
                            {
                                ParseDuration    = parseTime,
                                GeometryDuration = geomTime,
                                // SceneDuration = sceneTime,
                                FileName            = ifcFile.Remove(0, Params.TestFileRoot.Length).TrimStart('\\'),
                                Entities            = model.Instances.Count,
                                IfcSchema           = header.FileSchema.Schemas.FirstOrDefault(),
                                IfcDescription      = String.Format("{0}, {1}", header.FileDescription.Description.FirstOrDefault(), header.FileDescription.ImplementationLevel),
                                GeometryEntries     = geomReader.ShapeInstances.Count(),
                                IfcLength           = ReadFileLength(ifcFile),
                                XbimLength          = ReadFileLength(xbimFilename),
                                SceneLength         = 0,
                                IfcProductEntries   = model.Instances.OfType <IIfcProduct>().Count(),
                                IfcSolidGeometries  = model.Instances.OfType <IIfcSolidModel>().Count(),
                                IfcMappedGeometries = model.Instances.OfType <IIfcMappedItem>().Count(),
                                BooleanGeometries   = model.Instances.OfType <IIfcBooleanResult>().Count(),
                                BReps       = model.Instances.OfType <IIfcFaceBasedSurfaceModel>().Count() + model.Instances.OfType <IIfcShellBasedSurfaceModel>().Count() + model.Instances.OfType <IIfcManifoldSolidBrep>().Count(),
                                Application = ohs == null ? "Unknown" : ohs.OwningApplication.ToString(),
                            };
                        }
                        model.Close();
                    }
                }

                catch (Exception ex)
                {
                    Logger.Error(String.Format("Problem converting file: {0}", ifcFile), ex);
                    result.Failed = true;
                }
                finally
                {
                    result.Errors = (from e in eventTrace.Events
                                     where (e.EventLevel == EventLevel.ERROR)
                                     select e).Count();
                    result.Warnings = (from e in eventTrace.Events
                                       where (e.EventLevel == EventLevel.WARN)
                                       select e).Count();
                    result.FileName = ifcFile.Remove(0, Params.TestFileRoot.Length).TrimStart('\\');
                    if (eventTrace.Events.Count > 0)
                    {
                        CreateLogFile(ifcFile, eventTrace.Events);
                    }


                    writer.WriteLine(result.ToCsv());
                    writer.Flush();
                }
                return(result);
            }
        }
 /// <summary>
 /// Add ProcessResult to the ProcessResultSet
 /// </summary>
 /// <param name="pR">ProcessResult</param>
 public void Add(ProcessResult pR)
 {
     set.Add(pR);
 }
Esempio n. 5
0
        private ProcessResult ProcessFile(string ifcFile, StreamWriter writer, ILogger <BatchProcessor> logger)
        {
            RemoveFiles(ifcFile);
            // using (var eventTrace = LoggerFactory.CreateEventTrace())
            {
                var result = new ProcessResult()
                {
                    Errors = -1
                };
                var watch = new Stopwatch();
                try
                {
                    watch.Start();
                    using (var model = ParseModelFile(ifcFile, Params.Caching, logger))
                    {
                        var parseTime    = watch.ElapsedMilliseconds;
                        var xbimFilename = BuildFileName(ifcFile, ".xbim");
                        var context      = new Xbim3DModelContext(model, logger: logger);
                        if (_params.MaxThreads > 0)
                        {
                            context.MaxThreads = _params.MaxThreads;
                        }
                        // context.CustomMeshingBehaviour = CustomMeshingBehaviour;
                        context.CreateContext();
                        //}
                        var geomTime = watch.ElapsedMilliseconds - parseTime;
                        //XbimSceneBuilder sb = new XbimSceneBuilder();
                        //string xbimSceneName = BuildFileName(ifcFile, ".xbimScene");
                        //sb.BuildGlobalScene(model, xbimSceneName);
                        // sceneTime = watch.ElapsedMilliseconds - geomTime;
                        var header = model.Header;
                        watch.Stop();
                        var ohs = model.Instances.OfType <IIfcOwnerHistory>().FirstOrDefault();
                        using (var geomReader = model.GeometryStore.BeginRead())
                        {
                            result = new ProcessResult
                            {
                                ParseDuration    = parseTime,
                                GeometryDuration = geomTime,
                                // SceneDuration = sceneTime,
                                FileName       = ifcFile.Remove(0, Params.TestFileRoot.Length).TrimStart('\\'),
                                Entities       = model.Instances.Count,
                                IfcSchema      = header.FileSchema.Schemas.FirstOrDefault(),
                                IfcDescription =
                                    string.Format("{0}, {1}", header.FileDescription.Description.FirstOrDefault(),
                                                  header.FileDescription.ImplementationLevel),
                                GeometryEntries     = geomReader.ShapeInstances.Count(),
                                IfcLength           = ReadFileLength(ifcFile),
                                XbimLength          = ReadFileLength(xbimFilename),
                                SceneLength         = 0,
                                IfcProductEntries   = model.Instances.OfType <IIfcProduct>().Count(),
                                IfcSolidGeometries  = model.Instances.OfType <IIfcSolidModel>().Count(),
                                IfcMappedGeometries = model.Instances.OfType <IIfcMappedItem>().Count(),
                                BooleanGeometries   = model.Instances.OfType <IIfcBooleanResult>().Count(),
                                BReps = model.Instances.OfType <IIfcFaceBasedSurfaceModel>().Count() +
                                        model.Instances.OfType <IIfcShellBasedSurfaceModel>().Count() + model.Instances
                                        .OfType <IIfcManifoldSolidBrep>().Count(),
                                Application = ohs == null ? "Unknown" : ohs.OwningApplication?.ApplicationFullName.ToString()
                            };
                        }
                    }
                }

                catch (Exception ex)
                {
                    logger.LogError(string.Format("Problem converting file: {0}", ifcFile), ex);
                    result.Failed           = true;
                    result.GeometryDuration = watch.ElapsedMilliseconds;
                }

                return(result);
            }
        }