Esempio n. 1
0
        /// <summary>
        /// 设置指定参数项
        /// </summary>
        /// <typeparam name="T">参数项数据类型</typeparam>
        /// <param name="groupName">参数组名称</param>
        /// <param name="parameterName">参数项名称</param>
        /// <param name="description">参数项描述</param>
        /// <param name="data">参数项数据</param>
        /// <exception cref="C3DException">没有指定参数组</exception>
        /// <returns>设置后的参数项</returns>
        public C3DParameter SetParameter <T>(String groupName, String parameterName, String description, T data)
        {
            C3DParameterGroup group = this.GetGroup(groupName);

            if (group == null)
            {
                throw new C3DException("No such parameter group!");
            }

            C3DParameter param = group[parameterName];

            if (param == null)
            {
                param = group.Add(parameterName, description);
            }
            else
            {
                if (description != null)
                {
                    param.Description = description;
                }
            }

            param.SetData <T>(data);

            return(param);
        }
Esempio n. 2
0
        private void UpdateHeaderAndParameters(C3DFile file)
        {
            file.Header.FirstDataSectionID = this._newDataStartBlockIndex;
            C3DParameter dataStart = file.Parameters["POINT", "DATA_START"];

            if (dataStart != null)
            {
                dataStart.InternalSetData <UInt16>(this._newDataStartBlockIndex);

                this._writer.Seek(this._dataStartOffset, SeekOrigin.Begin);
                this._writer.Write(dataStart.GetLastDataArrayWithoutDescrption());
            }
        }
Esempio n. 3
0
        public C3DParameterDictionary ReadParameters()
        {
            Dictionary <Int32, C3DParameterGroup>    groups     = new Dictionary <Int32, C3DParameterGroup>();
            Dictionary <Int32, List <C3DParameter> > parameters = new Dictionary <Int32, List <C3DParameter> >();

            Int32 startPosition = (this._firstParameterBlockIndex - 1) * C3DConstants.FILE_SECTION_SIZE;

            this._reader.BaseStream.Seek(startPosition + 2, SeekOrigin.Begin);

            Byte paramsBlocksCount = this._reader.ReadByte();
            Byte processorType     = this._reader.ReadByte();

            Int64 endPosition  = startPosition + paramsBlocksCount * C3DConstants.FILE_SECTION_SIZE;
            Int16 nextPosition = 0;

            do
            {
                SByte   nameLength = this._reader.ReadSByte();//Byte 1
                Boolean isLocked   = nameLength < 0;
                nameLength = Math.Abs(nameLength);

                SByte  id   = this._reader.ReadSByte();           //Byte 2
                Byte[] name = this._reader.ReadBytes(nameLength); //Byte 3

                nextPosition = this._reader.ReadInt16();          //Byte 3 + n
                Byte[] lastData = (nextPosition > 0 ? this._reader.ReadBytes(nextPosition - 2) : null);

                if (id > 0)//C3DParameter
                {
                    C3DParameter parameter = new C3DParameter(this._processorType, id, name, isLocked, lastData);

                    List <C3DParameter> list = null;
                    if (!parameters.TryGetValue(parameter.ID, out list))
                    {
                        list = new List <C3DParameter>();
                    }

                    list.Add(parameter);
                    parameters[parameter.ID] = list;
                }
                else//C3DParameterGroup
                {
                    C3DParameterGroup group = new C3DParameterGroup(id, name, isLocked, lastData);
                    groups[-group.ID] = group;
                }
            }while (nextPosition > 0 && this._reader.BaseStream.Position < endPosition);

            return(C3DParameterDictionary.CreateParameterDictionaryFromParameterList(groups, parameters));
        }
Esempio n. 4
0
        private T[] LoadFromArray <T>(C3DParameter parameter, Int32 size)
        {
            Object raw = (parameter != null ? parameter.GetData() : null);

            T[] ret = null;

            if (raw != null && raw is T[])
            {
                ret = raw as T[];
            }
            else if (raw != null && raw is T && size > 0)
            {
                ret = new T[size];
                T unit = (T)raw;

                for (Int32 i = 0; i < ret.Length; i++)
                {
                    ret[i] = unit;
                }
            }

            return(ret);
        }
Esempio n. 5
0
        /// <summary>
        /// 获取指定路径的参数项的数据
        /// </summary>
        /// <param name="parameterPath">分号(:)分隔的参数项路径</param>
        /// <returns>指定路径的参数项的数据</returns>
        public T GetParameterData <T>(String parameterPath)
        {
            C3DParameter param = this[parameterPath];

            return(param != null ? param.GetData <T>() : default(T));
        }
Esempio n. 6
0
        /// <summary>
        /// 获取指定参数项的数据
        /// </summary>
        /// <param name="groupName">参数组名称</param>
        /// <param name="parameterName">参数项名称</param>
        /// <returns>指定参数项的数据</returns>
        public T GetParameterData <T>(String groupName, String parameterName)
        {
            C3DParameter param = this[groupName, parameterName];

            return(param != null ? param.GetData <T>() : default(T));
        }