Esempio n. 1
0
        private ProcessResult ProcessFile(string ifcFile, StreamWriter writer)
        {
            RemoveFiles(ifcFile);
            long geomTime = -1; long sceneTime = -1; long parseTime = -1;
            using (EventTrace eventTrace = LoggerFactory.CreateEventTrace())
            {
                ProcessResult result = new ProcessResult() { Errors = -1 };
                try
                {

                    Stopwatch watch = new Stopwatch();
                    watch.Start();
                    using (XbimModel model = ParseModelFile(ifcFile,Params.Caching))
                    {
                        parseTime = watch.ElapsedMilliseconds;
                        string xbimFilename = BuildFileName(ifcFile, ".xbim");
                        //model.Open(xbimFilename, XbimDBAccess.ReadWrite);
                        XbimMesher.GenerateGeometry(model, Logger, null);
                        geomTime = watch.ElapsedMilliseconds - parseTime;
                        XbimSceneBuilder sb = new XbimSceneBuilder();
                        string xbimSceneName = BuildFileName(ifcFile, ".xbimScene");
                        sb.BuildGlobalScene(model, xbimSceneName);
                        sceneTime = watch.ElapsedMilliseconds - geomTime;
                        IIfcFileHeader header = model.Header;
                        watch.Stop();
                        IfcOwnerHistory ohs = model.Instances.OfType<IfcOwnerHistory>().FirstOrDefault();
                        result = new ProcessResult()
                        {
                            ParseDuration = parseTime,
                            GeometryDuration = geomTime,
                            SceneDuration = sceneTime,
                            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.GeometriesCount,
                            IfcLength = ReadFileLength(ifcFile),
                            XbimLength = ReadFileLength(xbimFilename),
                            SceneLength = ReadFileLength(xbimSceneName),
                            IfcProductEntries = model.Instances.CountOf<IfcProduct>(),
                            IfcSolidGeometries = model.Instances.CountOf<IfcSolidModel>(),
                            IfcMappedGeometries = model.Instances.CountOf<IfcMappedItem>(),
                            BooleanGeometries = model.Instances.CountOf<IfcBooleanResult>(),
                            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;
                    if (eventTrace.Events.Count > 0)
                    {
                        CreateLogFile(ifcFile, eventTrace.Events);
                    }

                    lock (thisLock)
                    {
                        writer.WriteLine(result.ToCsv());
                        writer.Flush();
                    }
                }
                return result;
            }
        }
Esempio n. 2
0
        static int Main(string[] args)
        {
            int totErrors = 0;
            // We need to use the logger early to initialise before we use EventTrace
            Logger.Debug("XbimConvert starting...");

                arguments = Params.ParseParams(args);

                if (!arguments.IsValid)
                {
                    return -1;
                }

            var SubMode = SearchOption.TopDirectoryOnly;
            if (arguments.ProcessSubDir)
                SubMode = SearchOption.AllDirectories;
            var files = Directory.GetFiles(arguments.specdir, arguments.specpart, SubMode);
            if (files.Length == 0)
            {
                Console.WriteLine("Invalid IFC filename or filter: {0}, current directory is: {1}", args[0], Directory.GetCurrentDirectory());
                return -1;
            }

            long parseTime = 0;
            long geomTime = 0;
            foreach (var origFileName in files)
            {
                using (EventTrace eventTrace = LoggerFactory.CreateEventTrace())
                {
                try
                {
                    Console.WriteLine("Starting conversion of {0}", origFileName);
                    Logger.InfoFormat("Starting conversion of {0}", origFileName);
                    string xbimFileName = BuildFileName(origFileName, ".xbim");
                    //string xbimGeometryFileName = BuildFileName(arguments.IfcFileName, ".xbimGC");
                    System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
                    ReportProgressDelegate progDelegate = delegate(int percentProgress, object userState)
                    {
                        if (!arguments.IsQuiet)
                        {
                            Console.Write(string.Format("{0:D5} Converted", percentProgress));
                            ResetCursor(Console.CursorTop);
                        }
                    };
                    watch.Start();
                    using (XbimModel model = ParseModelFile(origFileName, xbimFileName, arguments.Caching))
                    {
                        //model.Open(xbimFileName, XbimDBAccess.ReadWrite);
                        parseTime = watch.ElapsedMilliseconds;
                        if (!arguments.NoGeometry)
                        {

                            XbimMesher.GenerateGeometry(model, Logger, progDelegate);
                            geomTime = watch.ElapsedMilliseconds - parseTime;
                            if (arguments.GenerateScene)
                            {
                                Stopwatch sceneTimer = new Stopwatch();
                                if (!arguments.IsQuiet)
                                    Console.Write("Scene generation started...");
                                sceneTimer.Start();
                                XbimSceneBuilder sb = new XbimSceneBuilder();
                                sb.Options = arguments.GenerateSceneOptions;
                                string xbimSceneName = BuildFileName(xbimFileName, ".xbimScene");
                                sb.BuildGlobalScene(model, xbimSceneName,
                                    !arguments.IsQuiet ? Logger : null
                                    );
                                sceneTimer.Stop();
                                if (!arguments.IsQuiet)
                                    Console.WriteLine(string.Format(" Completed in {0} ms", sceneTimer.ElapsedMilliseconds));

                            }
                        }
                        model.Close();
                        watch.Stop();
                    }

                   // XbimModel.Terminate();
                    GC.Collect();
                    ResetCursor(Console.CursorTop + 1);
                    Console.WriteLine("Success. Parsed in " + parseTime + " ms, geometry meshed in " + geomTime + " ms, total time " + (parseTime+geomTime) + " ms.");
                }
                catch (Exception e)
                {
                        if (e is XbimException || e is NotImplementedException)
                    {
                         // Errors we have already handled or know about. Keep details brief in the log
                            Logger.ErrorFormat("One or more errors converting {0}. Exiting...", origFileName);
                            CreateLogFile(origFileName, eventTrace.Events);

                            DisplayError(string.Format("One or more errors converting {0}, {1}", origFileName, e.Message));
                    }
                    else
                    {
                        // Unexpected failures. Log exception details
                            Logger.Fatal(String.Format("Fatal Error converting {0}. Exiting...", origFileName), e);
                            CreateLogFile(origFileName, eventTrace.Events);

                            DisplayError(string.Format("Fatal Error converting {0}, {1}", origFileName, e.Message));
                    }
                }
                int errors = (from e in eventTrace.Events
                             where (e.EventLevel > EventLevel.INFO)
                             select e).Count();
                if (errors > 0)
                {
                        CreateLogFile(origFileName, eventTrace.Events);
                    }
                    totErrors += errors;
                }
            }
            GetInput();
            Logger.Info("XbimConvert finished successfully...");
            return totErrors;
        }