Beispiel #1
0
        /// <summary>
        /// Adds a custom <see cref="HeaderVariable">HeaderVariable</see> to the list.
        /// </summary>
        /// <param name="variable">Header variable to add to the list.</param>
        public void AddCustomVariable(HeaderVariable variable)
        {
            if (variable == null)
            {
                throw new ArgumentNullException(nameof(variable), "The header variable cannot be null.");
            }

            this.customVariables.Add(variable.Name, variable);
        }
        /// <summary>
        /// Adds a custom <see cref="HeaderVariable">HeaderVariable</see> to the list.
        /// </summary>
        /// <param name="variable">Header variable to add to the list.</param>
        /// <remarks>
        /// All header variable names must start with the character '$'.<br />
        /// Header variable names that already exists in the known list cannot be added.
        /// </remarks>
        public void AddCustomVariable(HeaderVariable variable)
        {
            if (variable == null)
            {
                throw new ArgumentNullException(nameof(variable), "A custom header variable cannot be null.");
            }

            if (!variable.Name.StartsWith("$"))
            {
                throw new ArgumentException("A header variable name must start with '$'.", nameof(variable));
            }

            if (this.variables.ContainsKey(variable.Name))
            {
                throw new ArgumentException("A known header variable with the same name already exists.", nameof(variable));
            }

            this.customVariables.Add(variable.Name, variable);
        }
 /// <summary>Gets the header variable associated with the specified name.</summary>
 /// <param name="name">The name of the header variable to get.</param>
 /// <param name="variable">When this method returns, contains the header variable associated with the specified name, if the name is found; otherwise, it contains null.</param>
 /// <returns>True if the list contains a header variable with the specified name; otherwise, false.</returns>
 public bool TryGetCustomVariable(string name, out HeaderVariable variable)
 {
     return(this.customVariables.TryGetValue(name, out variable));
 }
        private void WriteSystemVariable(HeaderVariable variable)
        {
            Debug.Assert(this.activeSection == DxfObjectCode.HeaderSection);

            string name = variable.Name;
            object value = variable.Value;

            switch (name)
            {
                case HeaderVariableCode.AcadVer:
                    this.chunk.Write(9, name);
                    this.chunk.Write(1, StringEnum.GetStringValue((DxfVersion) value));
                    break;
                case HeaderVariableCode.HandleSeed:
                    this.chunk.Write(9, name);
                    this.chunk.Write(5, value);
                    break;
                case HeaderVariableCode.Angbase:
                    this.chunk.Write(9, name);
                    this.chunk.Write(50, value);
                    break;
                case HeaderVariableCode.Angdir:
                    this.chunk.Write(9, name);
                    this.chunk.Write(70, (short) (AngleDirection) value);
                    break;
                case HeaderVariableCode.AttMode:
                    this.chunk.Write(9, name);
                    this.chunk.Write(70, (short) (AttMode) value);
                    break;
                case HeaderVariableCode.AUnits:
                    this.chunk.Write(9, name);
                    this.chunk.Write(70, (short) (AngleUnitType) value);
                    break;
                case HeaderVariableCode.AUprec:
                    this.chunk.Write(9, name);
                    this.chunk.Write(70, value);
                    break;
                case HeaderVariableCode.CeColor:
                    this.chunk.Write(9, name);
                    this.chunk.Write(62, ((AciColor) value).Index);
                    break;
                case HeaderVariableCode.CeLtScale:
                    this.chunk.Write(9, name);
                    this.chunk.Write(40, value);
                    break;
                case HeaderVariableCode.CeLtype:
                    this.chunk.Write(9, name);
                    this.chunk.Write(6, this.EncodeNonAsciiCharacters((string) value));
                    break;
                case HeaderVariableCode.CeLweight:
                    this.chunk.Write(9, name);
                    this.chunk.Write(370, ((Lineweight) value).Value);
                    break;
                case HeaderVariableCode.CLayer:
                    this.chunk.Write(9, name);
                    this.chunk.Write(8, this.EncodeNonAsciiCharacters((string) value));
                    break;
                case HeaderVariableCode.CMLJust:
                    this.chunk.Write(9, name);
                    this.chunk.Write(70, (short) (MLineJustification) value);
                    break;
                case HeaderVariableCode.CMLScale:
                    this.chunk.Write(9, name);
                    this.chunk.Write(40, value);
                    break;
                case HeaderVariableCode.CMLStyle:
                    this.chunk.Write(9, name);
                    this.chunk.Write(2, this.EncodeNonAsciiCharacters((string) value));
                    break;
                case HeaderVariableCode.DimStyle:
                    this.chunk.Write(9, name);
                    this.chunk.Write(2, this.EncodeNonAsciiCharacters((string) value));
                    break;
                case HeaderVariableCode.TextSize:
                    this.chunk.Write(9, name);
                    this.chunk.Write(40, value);
                    break;
                case HeaderVariableCode.TextStyle:
                    this.chunk.Write(9, name);
                    this.chunk.Write(7, this.EncodeNonAsciiCharacters((string) value));
                    break;
                case HeaderVariableCode.LastSavedBy:
                    if (this.doc.DrawingVariables.AcadVer <= DxfVersion.AutoCad2000) break;
                    this.chunk.Write(9, name);
                    this.chunk.Write(1, this.EncodeNonAsciiCharacters((string) value));
                    break;
                case HeaderVariableCode.LUnits:
                    this.chunk.Write(9, name);
                    this.chunk.Write(70, (short) (LinearUnitType) value);
                    break;
                case HeaderVariableCode.LUprec:
                    this.chunk.Write(9, name);
                    this.chunk.Write(70, value);
                    break;
                case HeaderVariableCode.DwgCodePage:
                    this.chunk.Write(9, name);
                    this.chunk.Write(3, value);
                    break;
                case HeaderVariableCode.Extnames:
                    this.chunk.Write(9, name);
                    this.chunk.Write(290, value);
                    break;
                case HeaderVariableCode.InsBase:
                    this.chunk.Write(9, name);
                    Vector3 pos = (Vector3) value;
                    this.chunk.Write(10, pos.X);
                    this.chunk.Write(20, pos.Y);
                    this.chunk.Write(30, pos.Z);
                    break;
                case HeaderVariableCode.InsUnits:
                    this.chunk.Write(9, name);
                    this.chunk.Write(70, (short) (DrawingUnits) value);
                    break;
                case HeaderVariableCode.LtScale:
                    this.chunk.Write(9, name);
                    this.chunk.Write(40, value);
                    break;
                case HeaderVariableCode.LwDisplay:
                    this.chunk.Write(9, name);
                    this.chunk.Write(290, value);
                    break;
                case HeaderVariableCode.PdMode:
                    this.chunk.Write(9, name);
                    this.chunk.Write(70, (short) (PointShape) value);
                    break;
                case HeaderVariableCode.PdSize:
                    this.chunk.Write(9, name);
                    this.chunk.Write(40, value);
                    break;
                case HeaderVariableCode.PLineGen:
                    this.chunk.Write(9, name);
                    this.chunk.Write(70, value);
                    break;
                case HeaderVariableCode.PsLtScale:
                    this.chunk.Write(9, name);
                    this.chunk.Write(70, value);
                    break;
                case HeaderVariableCode.TdCreate:
                    this.chunk.Write(9, name);
                    this.chunk.Write(40, DrawingTime.ToJulianCalendar((DateTime) value));
                    break;
                case HeaderVariableCode.TduCreate:
                    this.chunk.Write(9, name);
                    this.chunk.Write(40, DrawingTime.ToJulianCalendar((DateTime) value));
                    break;
                case HeaderVariableCode.TdUpdate:
                    this.chunk.Write(9, name);
                    this.chunk.Write(40, DrawingTime.ToJulianCalendar((DateTime) value));
                    break;
                case HeaderVariableCode.TduUpdate:
                    this.chunk.Write(9, name);
                    this.chunk.Write(40, DrawingTime.ToJulianCalendar((DateTime) value));
                    break;
                case HeaderVariableCode.TdinDwg:
                    this.chunk.Write(9, name);
                    this.chunk.Write(40, ((TimeSpan) value).TotalDays);
                    break;
            }
        }
Beispiel #5
0
 public void WriteSystemVariable(HeaderVariable variable)
 {
     if (this.activeSection != StringCode.HeaderSection)
     {
         throw new InvalidDxfSectionException(this.activeSection, this.file);
     }
     this.WriteCodePair(HeaderVariable.NAME_CODE_GROUP, variable.Name);
     this.WriteCodePair(variable.CodeGroup, variable.Value);
 }