コード例 #1
0
        internal void UpdateHeader(IIfcFileHeader ifcFileHeader, long entityCount)
        {
            MemoryStream ms = new MemoryStream(4096);
            BinaryWriter bw = new BinaryWriter(ms);

            ifcFileHeader.Write(bw);
            if (!Api.TryMoveFirst(_jetSession, _jetCursor)) //there is nothing in
            {
                using (var update = new Update(_jetSession, _jetCursor, JET_prep.Insert))
                {
                    Api.SetColumn(_jetSession, _jetCursor, _colIdHeaderData, ms.ToArray());
                    Api.SetColumn(_jetSession, _jetCursor, _colIdEntityCount, entityCount);
                    Api.SetColumn(_jetSession, _jetCursor, _colIdFileVersion, XbimDatabaseVersion, Encoding.ASCII);
                    update.Save();
                }
            }
            else
            {
                using (var update = new Update(_jetSession, _jetCursor, JET_prep.Replace))
                {
                    Api.SetColumn(_jetSession, _jetCursor, _colIdHeaderData, ms.ToArray());
                    Api.SetColumn(_jetSession, _jetCursor, _colIdEntityCount, entityCount);
                    Api.SetColumn(_jetSession, _jetCursor, _colIdFileVersion, XbimDatabaseVersion, Encoding.ASCII);
                    update.Save();
                }
            }
        }
コード例 #2
0
        internal void WriteHeader(IIfcFileHeader ifcFileHeader)
        {
            MemoryStream ms = new MemoryStream(4096);
            BinaryWriter bw = new BinaryWriter(ms);

            ifcFileHeader.Write(bw);
            if (Api.TryMoveFirst(sesid, globalsTable))
            {
                using (var update = new Update(sesid, globalsTable, JET_prep.Replace))
                {
                    Api.SetColumn(sesid, globalsTable, ifcHeaderColumn, ms.ToArray());
                    update.Save();
                }
            }
        }
コード例 #3
0
        public void Write(XbimModel model, XmlWriter output)
        {
            try
            {
                _written = new HashSet <long>();

                output.WriteStartDocument();
                output.WriteStartElement("ex", "iso_10303_28", _iso10303urn);
                output.WriteAttributeString("version", "2.0");
                output.WriteAttributeString("xmlns", "xsi", null, _xsi);
                output.WriteAttributeString("xmlns", "xlink", null, _xlink);
                output.WriteAttributeString("xmlns", "ex", null, _iso10303urn);
                output.WriteAttributeString("xsi", "schemaLocation", null,
                                            string.Format("{0} {1}", _iso10303urn, _exXSD));

                _fileHeader = model.Header;
                WriteISOHeader(output);
                //Write out the uos
                output.WriteStartElement("uos", _namespace);
                output.WriteAttributeString("id", "uos_1");
                output.WriteAttributeString("description", "Xbim IfcXml Export");
                output.WriteAttributeString("configuration", "i_ifc2x3");
                output.WriteAttributeString("edo", "");
                output.WriteAttributeString("xmlns", "ex", null, _iso10303urn);
                output.WriteAttributeString("xmlns", "ifc", null, _namespace);
                output.WriteAttributeString("xsi", "schemaLocation", null, string.Format("{0} {1}", _namespace, _ifcXSD));

                foreach (var item in model.InstanceHandles)
                {
                    Write(model, item.EntityLabel, output);
                }

                output.WriteEndElement(); //uos
                output.WriteEndElement(); //iso_10303_28
                output.WriteEndDocument();
            }
            catch (Exception e)
            {
                throw new Exception("Failed to write IfcXml file", e);
            }
            finally
            {
                _written = null;
            }
        }
コード例 #4
0
        public void Write(XbimModel model, XmlWriter output)
        {
            try
            {
                _written = new HashSet<long>();

                output.WriteStartDocument();
                output.WriteStartElement("ex", "iso_10303_28", _iso10303urn);
                output.WriteAttributeString("version", "2.0");
                output.WriteAttributeString("xmlns", "xsi", null, _xsi);
                output.WriteAttributeString("xmlns", "xlink", null, _xlink);
                output.WriteAttributeString("xmlns", "ex", null, _iso10303urn);
                output.WriteAttributeString("xsi", "schemaLocation", null,
                                            string.Format("{0} {1}", _iso10303urn, _exXSD));

                _fileHeader = model.Header;
                WriteISOHeader(output);
                //Write out the uos
                output.WriteStartElement("uos", _namespace);
                output.WriteAttributeString("id", "uos_1");
                output.WriteAttributeString("description", "Xbim IfcXml Export");
                output.WriteAttributeString("configuration", "i_ifc2x3");
                output.WriteAttributeString("edo", "");
                output.WriteAttributeString("xmlns", "ex", null, _iso10303urn);
                output.WriteAttributeString("xmlns", "ifc", null, _namespace);
                output.WriteAttributeString("xsi", "schemaLocation", null, string.Format("{0} {1}", _namespace, _ifcXSD));

                foreach (var item in model.InstanceHandles)
                {
                    Write(model, item.EntityLabel, output);
                }

                output.WriteEndElement(); //uos
                output.WriteEndElement(); //iso_10303_28
                output.WriteEndDocument();
            }
            catch (Exception e)
            {
                throw new Exception("Failed to write IfcXml file", e);
            }
            finally
            {
                _written = null;
            }
        }
コード例 #5
0
 internal void UpdateHeader(IIfcFileHeader ifcFileHeader, long entityCount)
 {
     MemoryStream ms = new MemoryStream(4096);
     BinaryWriter bw = new BinaryWriter(ms);
     ifcFileHeader.Write(bw);
     if (!Api.TryMoveFirst(_jetSession, _jetCursor)) //there is nothing in
     {
         using (var update = new Update(_jetSession, _jetCursor, JET_prep.Insert))
         {
             Api.SetColumn(_jetSession, _jetCursor, _colIdHeaderData, ms.ToArray());
             Api.SetColumn(_jetSession, _jetCursor, _colIdEntityCount, entityCount);
             Api.SetColumn(_jetSession, _jetCursor, _colIdFileVersion, XbimDatabaseVersion, Encoding.ASCII);
             update.Save();
         }
     }
     else
     {
         using (var update = new Update(_jetSession, _jetCursor, JET_prep.Replace))
         {
             Api.SetColumn(_jetSession, _jetCursor, _colIdHeaderData, ms.ToArray());
             Api.SetColumn(_jetSession, _jetCursor, _colIdEntityCount, entityCount);
             Api.SetColumn(_jetSession, _jetCursor, _colIdFileVersion, XbimDatabaseVersion, Encoding.ASCII);
             update.Save();
         }
     }
 }
コード例 #6
0
        private string HeaderAsString(IIfcFileHeader header)
        {
            StringBuilder headerStr = new StringBuilder();
            headerStr.AppendLine("ISO-10303-21;");
            headerStr.AppendLine("HEADER;");
            //FILE_DESCRIPTION
            headerStr.Append("FILE_DESCRIPTION ((");
            int i = 0;

            if (header.FileDescription.Description.Count == 0)
            {
                headerStr.Append(@"''");
            }
            else
            {
                foreach (string item in header.FileDescription.Description)
                {
                    headerStr.AppendFormat(@"{0}'{1}'", i == 0 ? "" : ",", IfcText.Escape(item));
                    i++;
                }
            }
            headerStr.AppendFormat(@"), '{0}');", header.FileDescription.ImplementationLevel);
            headerStr.AppendLine();
            //FileName
            headerStr.Append("FILE_NAME (");
            headerStr.AppendFormat(@"'{0}'", (header.FileName !=null && header.FileName.Name!=null)? IfcText.Escape(header.FileName.Name):"");
            headerStr.AppendFormat(@", '{0}'", header.FileName !=null? header.FileName.TimeStamp:"");
            headerStr.Append(", (");
            i = 0;
            if (header.FileName.AuthorName.Count == 0)
                headerStr.Append(@"''");
            else
            {
                foreach (string item in header.FileName.AuthorName)
                {
                    headerStr.AppendFormat(@"{0}'{1}'", i == 0 ? "" : ",", IfcText.Escape(item));
                    i++;
                }
            }
            headerStr.Append("), (");
            i = 0;
            if (header.FileName.Organization.Count == 0)
                headerStr.Append(@"''");
            else
            {
                foreach (string item in header.FileName.Organization)
                {
                    headerStr.AppendFormat(@"{0}'{1}'", i == 0 ? "" : ",", IfcText.Escape(item));
                    i++;
                }
            }
            headerStr.AppendFormat(@"), '{0}', '{1}', '{2}');", IfcText.Escape(header.FileName.PreprocessorVersion), IfcText.Escape(header.FileName.OriginatingSystem),
                                IfcText.Escape(header.FileName.AuthorizationName));
            headerStr.AppendLine();
            //FileSchema
            headerStr.AppendFormat("FILE_SCHEMA (('{0}'));", header.FileSchema.Schemas.FirstOrDefault());
            headerStr.AppendLine();
            headerStr.AppendLine("ENDSEC;");
            headerStr.AppendLine("DATA;");
            return headerStr.ToString();
        }
コード例 #7
0
        private string HeaderAsString(IIfcFileHeader header)
        {
            StringBuilder headerStr = new StringBuilder();

            headerStr.AppendLine("ISO-10303-21;");
            headerStr.AppendLine("HEADER;");
            //FILE_DESCRIPTION
            headerStr.Append("FILE_DESCRIPTION ((");
            int i = 0;

            if (header.FileDescription.Description.Count == 0)
            {
                headerStr.Append(@"''");
            }
            else
            {
                foreach (string item in header.FileDescription.Description)
                {
                    headerStr.AppendFormat(@"{0}'{1}'", i == 0 ? "" : ",", IfcText.Escape(item));
                    i++;
                }
            }
            headerStr.AppendFormat(@"), '{0}');", header.FileDescription.ImplementationLevel);
            headerStr.AppendLine();
            //FileName
            headerStr.Append("FILE_NAME (");
            headerStr.AppendFormat(@"'{0}'", (header.FileName != null && header.FileName.Name != null)? IfcText.Escape(header.FileName.Name):"");
            headerStr.AppendFormat(@", '{0}'", header.FileName != null? header.FileName.TimeStamp:"");
            headerStr.Append(", (");
            i = 0;
            if (header.FileName.AuthorName.Count == 0)
            {
                headerStr.Append(@"''");
            }
            else
            {
                foreach (string item in header.FileName.AuthorName)
                {
                    headerStr.AppendFormat(@"{0}'{1}'", i == 0 ? "" : ",", IfcText.Escape(item));
                    i++;
                }
            }
            headerStr.Append("), (");
            i = 0;
            if (header.FileName.Organization.Count == 0)
            {
                headerStr.Append(@"''");
            }
            else
            {
                foreach (string item in header.FileName.Organization)
                {
                    headerStr.AppendFormat(@"{0}'{1}'", i == 0 ? "" : ",", IfcText.Escape(item));
                    i++;
                }
            }
            headerStr.AppendFormat(@"), '{0}', '{1}', '{2}');", IfcText.Escape(header.FileName.PreprocessorVersion), IfcText.Escape(header.FileName.OriginatingSystem),
                                   IfcText.Escape(header.FileName.AuthorizationName));
            headerStr.AppendLine();
            //FileSchema
            headerStr.AppendFormat("FILE_SCHEMA (('{0}'));", header.FileSchema.Schemas.FirstOrDefault());
            headerStr.AppendLine();
            headerStr.AppendLine("ENDSEC;");
            headerStr.AppendLine("DATA;");
            return(headerStr.ToString());
        }
コード例 #8
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 (XbimModel model = ParseModelFile(ifcFile, Params.Caching))
                    {
                        parseTime = watch.ElapsedMilliseconds;
                        string xbimFilename = BuildFileName(ifcFile, ".xbim");
                        //model.Open(xbimFilename, XbimDBAccess.ReadWrite);
                        //if (_params.GeometryV1)
                        //    XbimMesher.GenerateGeometry(model, Logger, null);
                        //else
                        //{
                        Xbim3DModelContext context = new Xbim3DModelContext(model);
                        context.CreateContext(XbimGeometryType.PolyhedronBinary);
                        //}
                        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.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     = model.GeometriesCount,
                            IfcLength           = ReadFileLength(ifcFile),
                            XbimLength          = ReadFileLength(xbimFilename),
                            SceneLength         = 0,
                            IfcProductEntries   = model.Instances.CountOf <IfcProduct>(),
                            IfcSolidGeometries  = model.Instances.CountOf <IfcSolidModel>(),
                            IfcMappedGeometries = model.Instances.CountOf <IfcMappedItem>(),
                            BooleanGeometries   = model.Instances.CountOf <IfcBooleanResult>(),
                            BReps       = model.Instances.CountOf <IfcFaceBasedSurfaceModel>() + model.Instances.CountOf <IfcShellBasedSurfaceModel>() + model.Instances.CountOf <IfcManifoldSolidBrep>(),
                            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);
            }
        }