Пример #1
0
        /// <summary>
        /// Writes model information from component bodies.
        /// </summary>
        /// <param name="library">Storage where serialize the model data.</param>
        private void WriteLibraryModels(CFStorage library)
        {
            var models = library.GetOrAddStorage("Models");
            var bodies = Data.Items.SelectMany(c => c.GetPrimitivesOfType <PcbComponentBody>(false))
                         .Where(c => c.ModelEmbed).ToList();

            WriteHeader(models, bodies.Count);
            models.GetOrAddStream("Data").Write(writer =>
            {
                for (var i = 0; i < bodies.Count; ++i)
                {
                    var body       = bodies[i];
                    var parameters = new ParameterCollection
                    {
                        { "ID", body.ModelId },
                        { "ROTX", body.Model3DRotX },
                        { "ROTY", body.Model3DRotY },
                        { "ROTZ", body.Model3DRotZ },
                        { "DZ", body.Model3DDz.ToInt32() },
                        { "CHECKSUM", body.ModelChecksum },
                        { "EMBED", body.ModelEmbed },
                        { "NAME", body.Identifier + ".STEP" },
                    };

                    WriteBlock(writer, w => WriteParameters(w, parameters));

                    // models are stored as ASCII STEP files but using zlib compression
                    var modelCompressedData = CompressZlibData(Encoding.ASCII.GetBytes(body.StepModel));
                    models.GetOrAddStream($"{i}").SetData(modelCompressedData);
                }
            });
        }
Пример #2
0
        private static void WriteUniqueIdPrimitiveInformation(CFStorage componentStorage, PcbComponent component)
        {
            var uniqueIdPrimitiveInformation = componentStorage.GetOrAddStorage("UniqueIdPrimitiveInformation");

            var primitives = component.Primitives.Where(p => !(p is PcbUnknown)).ToList();

            WriteHeader(uniqueIdPrimitiveInformation, primitives.Count);

            uniqueIdPrimitiveInformation.GetOrAddStream("Data").Write(writer =>
            {
                for (int i = 0; i < primitives.Count; ++i)
                {
                    var primitive  = primitives[i];
                    var parameters = new ParameterCollection
                    {
                        { "PRIMITIVEINDEX", i },
                        { "PRIMITIVEOBJECTID", primitive.ObjectId.ToString() },
                        { "UNIQUEID", primitive.UniqueId }
                    };
                    WriteBlock(writer, w => WriteParameters(w, parameters));
                }
            });
        }