예제 #1
0
        /// <summary>
        /// Writes full model into output writer as STEP21 file
        /// </summary>
        /// <param name="model">Model to be serialized</param>
        /// <param name="output">Output writer</param>
        /// <param name="metadata">Metadata to be used for serialization</param>
        /// <param name="map">Optional map can be used to map occurrences in the file</param>
        private void Write(TextWriter output)
        {
            ExpressMetaData metadata       = Metadata;
            var             header         = Header ?? new StepFileHeader(StepFileHeader.HeaderCreationMode.InitWithXbimDefaults, this);
            string          fallBackSchema = EntityFactory.SchemasIds.FirstOrDefault();

            if (!header.FileSchema.Schemas.Any())
            {
                foreach (var id in EntityFactory.SchemasIds)
                {
                    header.FileSchema.Schemas.Add(id);
                }
            }

            Part21Writer.WriteHeader(header, output, fallBackSchema);

            foreach (var entity in Instances)
            {
                if (_comments.TryGetValue(entity.EntityLabel, out string comment))
                {
                    comment = comment.Trim('\r', '\n');
                    comment = comment.Replace("\r\n", "\r\n* ");
                    output.WriteLine();
                    output.WriteLine($"/**");
                    output.WriteLine("* " + comment);
                    output.WriteLine($"* {GetMetaComment(entity)}*/");
                }
                Part21Writer.WriteEntity(entity, output, metadata, null);
                output.WriteLine();
            }
            Part21Writer.WriteFooter(output);
        }
예제 #2
0
        private string GetEntityString()
        {
            Part21Writer.WriteEntity(_entity, _writer, _entity.Model.Metadata, _dummy);
            var value = _writer.ToString();

            ClearWriter();
            return(value);
        }
예제 #3
0
 /// <summary>
 /// Saves a model as a STEP IFC file
 /// </summary>
 /// <param name="model"></param>
 /// <param name="stream"></param>
 /// <param name="progDelegate"></param>
 public static void SaveAsIfc(this IModel model, Stream stream, ReportProgressDelegate progDelegate = null)
 {
     using (TextWriter tw = new StreamWriter(stream))
     {
         Part21Writer.Write(model, tw, model.Metadata, null, progDelegate);
         tw.Flush();
     }
 }
예제 #4
0
        private string GetPropertyString(int order)
        {
            var info = _changedProperties[order];

            Part21Writer.WriteProperty(info.PropertyType, info.GetValue(_entity, null), _writer, _dummy, _entity.Model.Metadata);
            var value = _writer.ToString();

            ClearWriter();
            return(value);
        }
예제 #5
0
        public static void Save(TextWriter writer, IModel model)
        {
            Part21Writer.WriteHeader(model.Header, writer, "IFC4");
            var metadata = model.Metadata;

            foreach (var instance in model.Instances)
            {
                WriteEntity(instance, writer, metadata);
            }
            Part21Writer.WriteFooter(writer);
        }
예제 #6
0
        public override string ToString()
        {
            ExpressMetaData md = null;

            if (Model != null)
            {
                md = Model.Metadata;
            }
            else
            {
                md = ExpressMetaData.GetMetadata(GetType().Module);
            }

            using (var sw = new StringWriter())
            {
                Part21Writer.WriteEntity(this, sw, md);
                return(sw.ToString());
            }
        }
예제 #7
0
        private static void WriteEntity(IPersistEntity entity, TextWriter output, ExpressMetaData metadata)
        {
            var expressType = metadata.ExpressType(entity);

            output.Write("#{0}={1}(", entity.EntityLabel, expressType.ExpressNameUpper);

            var first = true;

            foreach (var ifcProperty in expressType.Properties.Values)
            //only write out persistent attributes, ignore inverses
            {
                if (ifcProperty.EntityAttribute.State == EntityAttributeState.DerivedOverride)
                {
                    if (!first)
                    {
                        output.Write(',');
                    }
                    output.Write('*');
                    first = false;
                }
                else
                {
                    // workaround for IfcCartesianPointList3D from IFC4x1
                    if (entity is IfcCartesianPointList3D && ifcProperty.Name == "TagList")
                    {
                        continue;
                    }

                    var propType = ifcProperty.PropertyInfo.PropertyType;
                    var propVal  = ifcProperty.PropertyInfo.GetValue(entity, null);
                    if (!first)
                    {
                        output.Write(',');
                    }
                    Part21Writer.WriteProperty(propType, propVal, output, null, metadata);
                    first = false;
                }
            }
            output.Write(");");
        }
예제 #8
0
        private static void WriteEntityRecursive(IPersistEntity entity, ExpressMetaData metadata, TextWriter writer, HashSet <int> written)
        {
            if (written.Contains(entity.EntityLabel))
            {
                return;
            }

            Part21Writer.WriteEntity(entity, writer, metadata);
            written.Add(entity.EntityLabel);

            var references = entity as IContainsEntityReferences;

            if (references == null)
            {
                return;
            }

            foreach (var item in references.References)
            {
                WriteEntityRecursive(item, metadata, writer, written);
            }
        }
예제 #9
0
 /// <summary>
 /// Saves the model as PART21 file
 /// </summary>
 /// <param name="writer">Text writer to be used to write the file</param>
 /// <param name="progress"></param>
 public virtual void SaveAsStep21(TextWriter writer, ReportProgressDelegate progress = null)
 {
     Part21Writer.Write(this, writer, Metadata, new Dictionary <int, int>());
 }
예제 #10
0
        public void TransactionLog()
        {
            using (var model = IfcStore.Create(IfcSchemaVersion.Ifc2X3, XbimStoreType.InMemoryModel))
            {
                var changed    = new List <string>();
                var valuesLog  = new StringWriter();
                var initialLog = new StringWriter();
                model.EntityModified += (entity, property) =>
                {
                    //use reflection to get property information for the changed property
                    var pInfo = entity.ExpressType.Properties[property];
                    changed.Add(pInfo.Name);

                    //express indices are 1 based
                    var propertyIndex = property - 1;

                    //overriden attributes have to be treated specially. But these are not present in CobieExpress.
                    if (pInfo.EntityAttribute.State == EntityAttributeState.DerivedOverride)
                    {
                        initialLog.Write("*");
                    }
                    else
                    {
                        //you can use reflection to get the current (new) value
                        var value = pInfo.PropertyInfo.GetValue(entity, null);

                        //this is part of the serialization engine but you can use it for a single property as well
                        Part21Writer.WriteProperty(pInfo.PropertyInfo.PropertyType, value, valuesLog, null, model.Metadata);
                    }

                    valuesLog.WriteLine();
                };
                model.EntityNew += entity =>
                {
                    //iterate over all properties. These are sorted in the right order already.
                    foreach (var property in entity.ExpressType.Properties.Values)
                    {
                        //overriden attributes have to be treated specially. But these are not present in CobieExpress.
                        if (property.EntityAttribute.State == EntityAttributeState.DerivedOverride)
                        {
                            initialLog.Write("*");
                        }
                        else
                        {
                            var value = property.PropertyInfo.GetValue(entity, null);
                            Part21Writer.WriteProperty(property.PropertyInfo.PropertyType, value, initialLog, null, model.Metadata);
                        }
                        initialLog.WriteLine();
                    }
                };
                using (var txn = model.BeginTransaction())
                {
                    var wall = model.Instances.New <IfcWall>();
                    wall.Name        = "New name";
                    wall.Description = null;

                    var pset = model.Instances.New <IfcPropertySet>();
                    pset.HasProperties.Add(model.Instances.New <IfcPropertySingleValue>());

                    Assert.IsTrue(changed.SequenceEqual(new [] { "Name", "Description", "HasProperties" }));
                    Assert.AreEqual(valuesLog.ToString(), "'New name'\r\n$\r\n(#3)\r\n");

                    txn.Commit();
                }
            }
        }