public static GeometryDataSerializer WriteEntity <T>(T entity)
        {
            GeometryDataSerializer stream = new GeometryDataSerializer();

            stream.WriteObject(entity);
            return(stream);
        }
        public IBSplineCurveEntity ReadBSplineCurve()
        {
            Object data     = GetData("ControlVertices");
            Array  vertices = data as Array;

            if (null == vertices)
            {
                throw new DataMisalignedException(string.Format("Invalid data : {0} for parameter {1}", data, "ControlVertices"));
            }

            GeometryDataSerializer stream = new GeometryDataSerializer(vertices);
            List <IPointEntity>    points = new List <IPointEntity>();

            foreach (var item in stream)
            {
                points.Add(stream.ReadPoint());
            }

            int  degree   = ReadInteger("Degree");
            bool periodic = ReadBoolean("IsPeriodic");

            IBSplineCurveEntity entity = HostFactory.Factory.BSplineByControlVertices(points.ToArray(), degree, periodic);

            points.ForEach(GeometryExtension.DisposeObject);
            return(entity);
        }
        void WriteEntity <T>(string parameter, T[] collection)
        {
            GeometryDataSerializer stream = new GeometryDataSerializer();
            int i = 0;

            foreach (var item in collection)
            {
                stream.WriteEntity(parameter + i, item);
                ++i;
            }
            WriteStream(parameter, stream, false); //writing as array
        }
        T ReadObject <T>(string parameter, Reader <GeometryDataSerializer, T> reader)
        {
            Array p = GetData(parameter) as Array;

            if (null == p)
            {
                throw new DataMisalignedException(string.Format("The data for parameter : {0} is not in {1} format.", parameter, reader));
            }

            GeometryDataSerializer stream = new GeometryDataSerializer(p);

            return(reader(stream));
        }
Пример #5
0
        public IContextData[] ImportData(Dictionary <string, object> connectionParameters)
        {
            List <Geometry> geometryList = new List <Geometry>();

            Geometry[] geometry = null;
            foreach (var param in connectionParameters)
            {
                switch (param.Key)
                {
                case "OBJ":
                    geometry = SubDivisionMesh.ImportFromOBJ(Convert.ToString(param.Value));
                    break;

                case "SAT":
                    geometry = Geometry.ImportFromSAT(Convert.ToString(param.Value));
                    break;

                default:
                    if (param.Value.GetType().IsArray)
                    {
                        Array data = param.Value as Array;
                        geometry = GeometryDataSerializer.CreateGeometryFromData(param.Key, data);
                    }
                    break;
                }
                if (null != geometry && geometry.Length > 0)
                {
                    geometryList.AddRange(geometry);
                }
            }

            int nItems = geometryList.Count;

            if (nItems == 0)
            {
                return(null);
            }

            IContextData[] contextData = new IContextData[nItems];
            for (int i = 0; i < nItems; ++i)
            {
                contextData[i] = new GeometryData("ImportData", geometryList[i], this);
            }
            return(contextData);
        }
        /// <summary>
        /// Creates geometry from given set of data
        /// </summary>
        /// <param name="geomType">Geometry type</param>
        /// <param name="data">Collection of input data to create geometry from</param>
        /// <returns>Collection of Geometry created using the given data</returns>
        public static Geometry[] CreateGeometryFromData(string geomType, Array data)
        {
            Func <GeometryDataSerializer, IDesignScriptEntity> reader = mSerializers.GetReader(geomType);

            if (reader == null)
            {
                return(null);
            }

            List <Geometry>        geometry = new List <Geometry>();
            GeometryDataSerializer stream   = new GeometryDataSerializer(data);

            while (!stream.DoneReading())
            {
                IGeometryEntity entity = reader(stream) as IGeometryEntity;
                geometry.Add(Geometry.ToGeometry(entity, true));
            }

            return(geometry.ToArray());
        }
        void WriteEntity <T>(string parameter, T entity)
        {
            GeometryDataSerializer stream = WriteEntity(entity);

            WriteStream(parameter, stream, keepInternalDataParametrized);
        }
 public void RegisterSerializers <T>(string type, Func <GeometryDataSerializer, IDesignScriptEntity> reader) where T : IDesignScriptEntity
 {
     mDataTypes.Add(typeof(T), type);
     mDataReaders.Add(type, reader);
     mDataWriters.Add(typeof(T), (IDesignScriptEntity e) => GeometryDataSerializer.WriteEntity((T)e));
 }