Beispiel #1
0
        public override void DeSerialize(XData raw)
        {
            var keyArray    = (string[])(XStringArray)raw;
            var newKeyArray = new string[keyArray.Length];

            // replace bad keys
            for (int i = 0; i < keyArray.Length; ++i)
            {
                if (uint.TryParse(keyArray[i], out uint keyId) && keyId > MaxKey)
                {
                    newKeyArray[i] = KeyCodeConverter.GetKey(KeyPlaceHolder);
                }
                else
                {
                    newKeyArray[i] = keyArray[i];
                }
            }

            base.DeSerialize(new XStringArray("", newKeyArray));
            for (int i = 0; i < keyArray.Length; ++i)
            {
                var key = keyArray[i];
                if (!uint.TryParse(key, out uint extKey) || extKey < MaxKey)
                {
                    continue;
                }

                UpdatedKeyCodes[i] = extKey;
            }
            UpdateText();
            InvokeKeysChanged();
        }
Beispiel #2
0
        public void SaveData(double xStart, double xIncrement, double[,] yData, int lineCount)
        {
            DataInfo.XDataInputType = XDataInputType.Increment;
            //            DataInfo.XDataType = XDataType.Number;
            XStart        = xStart;
            XIncrement    = xIncrement;
            DataInfo.Size = yData.GetLength(1);

            MaxXValue = xStart + (DataInfo.Size - 1) * xIncrement;
            MinXValue = xStart;

            XMinInterval = xIncrement > Constants.MinLegalInterval ? xIncrement : Constants.MinLegalInterval;

            //            InitYDataBuf(yData, yDataSize);
            DataInfo.LineNum = lineCount;

            XData?.Clear();
            if (null == _transBuf || _transBuf.Length != yData.Length)
            {
                _transBuf = new double[yData.Length];
            }
            Buffer.BlockCopy(yData, 0, _transBuf, 0, lineCount * DataInfo.Size * sizeof(double));
            YData = SaveDataToBuf(YData, _transBuf);

            PerformDataCheck();

            //            YStrData = null;

            PlotBuf.AdaptPlotBuffer();

            InitViewRange();
        }
Beispiel #3
0
        public void GetData()
        {
            if (m_settings.settings["liveSession"] == "true" && selectDate == DateTime.Today)
            { // got provide live data
            }
            else
            {
                string minPath = m_dataFolder + @"min\" + selectDate.ToString("yyyy") + @"\" + selectDate.ToString("yyyy-MM-dd") + @"\" + selectTicker + ".txt";
                if (File.Exists(minPath))
                {
                    string[] lines = File.ReadAllLines(minPath);

                    foreach (string line in lines)
                    {
                        string[]       parts = line.Split(new char[] { ',' });
                        DateTime       dt    = Convert.ToDateTime(parts[0]);
                        DateTimeOffset dto   = new DateTimeOffset(dt);
                        XData       = XData + "," + dto.ToUnixTimeSeconds().ToString();
                        YDataPrice  = YDataPrice + "," + parts[1];
                        YDataVolume = YDataVolume + "," + parts[2];
                    }

                    //remove starting ,
                    XData       = XData.Substring(1);
                    YDataPrice  = YDataPrice.Substring(1);
                    YDataVolume = YDataVolume.Substring(1);
                }
                else
                {
                    XData       = ""; YDataVolume = ""; YDataPrice = "";
                    noDataFound = true;
                }
            }
        }
Beispiel #4
0
        private void MeasureThread()
        {
            m_Measure_thread_exit = false;

            while (!m_Measure_thread_exit)
            {
                xdata = new XData();
                bool success = recieve_data(ref xdata);
                if (!success || !string.IsNullOrEmpty(xdata.error_msg))
                {
                    //LogWrite("Receive data failed: " + xdata.error_msg);
                    Thread.Sleep(30);
                    continue;
                }

                MeasureInvoke inInvoke = new MeasureInvoke(UpdateMeasureInfo);
                try
                {
                    this.Invoke(inInvoke);
                    //BeginInvoke(inInvoke);
                }
                catch (Exception e)
                {
                    LogWrite("MeasureThread catch");
                    LogWrite(e.ToString());
                }
            }

            LogWrite("MeasureThread exit!");
            m_Measure_thread_exit = true;
            client.Close();
        }
Beispiel #5
0
        private void LoadConfiguration()
        {
            if (Controller.Instance.MI == null)
            {
                return;
            }

            foreach (var blockinfo in Controller.Instance.MI.Blocks)
            {
                if (blockinfo.Guid == BB.Guid)
                {
                    XDataHolder bd = blockinfo.BlockData;

                    try { BlockDataLoadEvent(bd); } catch { };

                    LoadConfiguration(bd);

                    foreach (MapperType item in myMapperTypes)
                    {
                        string str    = string.Concat(MapperType.XDATA_PREFIX + item.Key);
                        XData  xDatum = bd.Read(str);
                        if (xDatum != null || !StatMaster.isPaste)
                        {
                            item.DeSerialize((xDatum == null ? item.defaultData : xDatum));
                        }
                    }

                    break;
                }
            }
        }
Beispiel #6
0
        static public void printxdata()
        {
            Editor   ed = Application.DocumentManager.MdiActiveDocument.Editor;
            ObjectId id = SelectEntity();//选择实体

            if (id == ObjectId.Null)
            {
                ed.WriteMessage("\n用户取消操作\n");
                return;
            }
            XData xdata = new XData(id);

            if (!xdata.HasXData())
            {
                Tools.WriteMessage("\n该实体不存在扩展数据\n");
                return;
            }

            bool isPrintAllXData = AskForPrintAllXData();

            if (isPrintAllXData)
            {
                xdata.PrintXDataList();
            }
            else
            {
                string appName = getAppName();//获取appname
                if (appName == null)
                {
                    ed.WriteMessage("\n用户取消操作\n");
                    return;
                }
                xdata.PrintXData(appName);
            }
        }
Beispiel #7
0
        public void Add(TEntity entity)
        {
            XDocument xDoc;

            using (StreamReader oReader = new StreamReader(fileName, Encoding.UTF8))
            {
                xDoc = XDocument.Load(oReader);
            }

            XElement rootElement = xDoc.Root;

            XElement newElement = new XElement(XData <TEntity> .RootName(entity));

            XAttribute idAttribute = new XAttribute("id", Info(entity).GetValue(entity).ToString());

            List <XElement> elements = new List <XElement>();

            foreach (var item in entity.GetType().GetProperties())
            {
                if (item.Name == XData <TEntity> .IdentityPattern)
                {
                    continue;
                }
                elements.Add(new XElement(item.Name, item.GetValue(entity)));
            }

            newElement.Add(idAttribute, elements);

            rootElement.Add(newElement);

            xDoc.Save(fileName);
        }
Beispiel #8
0
        public void SetTextNull()
        {
            var x = new XData();

            // allowed.
            x.Text = null;
        }
Beispiel #9
0
        public Poco_I GetById(long id)
        {
            var api = (AssociationApi_I)XData.GetApi <Association_I>();

            // From type id, get data api
            return(api.GetById(id));
        }
Beispiel #10
0
        public List <Poco_I> GetAllTo(long toId, long associtionTypaId)
        {
            var api = (AssociationApi_I)XData.GetApi <Association_I>();

            // From type id, get data api
            return(api.GetAllTo(toId, associtionTypaId));
        }
Beispiel #11
0
        public void GetXmlReaderWithNullText()
        {
            var x = new XData();

            Assert.IsNull(x.Text, "#1");
            Assert.Throws <ArgumentNullException> (() => { var xr = x.XmlReader; }, "#2");
        }
        /// <summary>
        /// Modifies or creates the xData hatch information entries that hold the values for the gradient color indexes.
        /// </summary>
        /// <param name="xdata">Hatch <see cref="XData">XData</see></param>
        public void GradientColorAciXData(Dictionary <string, XData> xdata)
        {
            if (xdata.ContainsKey("GradientColor1ACI"))
            {
                XData       xdataEntry = xdata["GradientColor1ACI"];
                XDataRecord record     = new XDataRecord(XDataCode.Integer, this.color1.Index);
                xdataEntry.XDataRecord.Clear();
                xdataEntry.XDataRecord.Add(record);
            }
            else
            {
                XData xdataEntry = new XData(new ApplicationRegistry("GradientColor1ACI"));
                xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Integer, this.Color1.Index));
                xdata.Add(xdataEntry.ApplicationRegistry.Name, xdataEntry);
            }

            if (xdata.ContainsKey("GradientColor2ACI"))
            {
                XData       xdataEntry = xdata["GradientColor2ACI"];
                XDataRecord record     = new XDataRecord(XDataCode.Integer, this.color2.Index);
                xdataEntry.XDataRecord.Clear();
                xdataEntry.XDataRecord.Add(record);
            }
            else
            {
                XData xdataEntry = new XData(new ApplicationRegistry("GradientColor2ACI"));
                xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Integer, this.color2.Index));
                xdata.Add(xdataEntry.ApplicationRegistry.Name, xdataEntry);
            }
        }
Beispiel #13
0
        public override void DeSerialize(XData raw)
        {
            var strArr      = (XStringArray)raw;
            var keyArray    = (string[])strArr;
            var newKeyArray = new List <string>();
            var oldIntKeys  = new List <string>();

            for (int i = 0; i < keyArray.Length; ++i)
            {
                // convert old int keys to message
                if (uint.TryParse(keyArray[i], out uint keyId) && keyId > KnownKeys.Max())
                {
                    oldIntKeys.Add(keyArray[i]);
                }
                else
                {
                    newKeyArray.Add(keyArray[i]);
                }
            }

            // Add Message=1000;1001... item if old mod int keys were found.
            // Both Message= and int keys should not be present in machine at the same time
            if (oldIntKeys.Count > 0)
            {
                newKeyArray.Add("Message=" + string.Join(";", oldIntKeys.ToArray()));
            }

            var converted = newKeyArray.ToArray();

            base.DeSerialize(new XStringArray(strArr.Key, converted));
            saveUseMessage = useMessage;
        }
Beispiel #14
0
        public override void SetXmlInstance(object inst, XamlMember property, XData xData)
        {
            IXmlSerializable serializable = this.GetValue(inst, property, true) as IXmlSerializable;

            if (serializable == null)
            {
                throw this.CreateException(System.Xaml.SR.Get("XmlDataNull", new object[] { property.Name }));
            }
            XmlReader xmlReader = xData.XmlReader as XmlReader;

            if (xmlReader == null)
            {
                throw new XamlInternalException(System.Xaml.SR.Get("XmlValueNotReader", new object[] { property.Name }));
            }
            try
            {
                serializable.ReadXml(xmlReader);
            }
            catch (Exception exception)
            {
                if (CriticalExceptions.IsCriticalException(exception))
                {
                    throw;
                }
                throw this.CreateException(System.Xaml.SR.Get("SetXmlInstance", new object[] { property }), exception);
            }
        }
Beispiel #15
0
        private void selectButton_Click(object sender, EventArgs e)
        {
            if (xdata != null)
            {
                xdata.UpdateXData();
            }

            //SetFocus(Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Window.Handle);

            this.Visible = false;
            this.Hide();//先隐藏窗体

            PromptEntityOptions prEnt    = new PromptEntityOptions("\n请选择一个实体 ");
            PromptEntityResult  prEntRes = Tools.Editor.GetEntity(prEnt);

            if (prEntRes.Status != PromptStatus.OK)
            {
                this.Visible = true;
                this.Show();
                return;
            }

            if (xdata == null || xdata.Id != prEntRes.ObjectId)
            {
                xdata = new XData(prEntRes.ObjectId);
                updateData();
            }

            this.Visible = true;
            this.Show();

            //SetFocus(this.Handle);
        }
Beispiel #16
0
        static public void getxdata()
        {
            Editor   ed = Application.DocumentManager.MdiActiveDocument.Editor;
            ObjectId id = SelectEntity();//选择实体

            if (id == ObjectId.Null)
            {
                ed.WriteMessage("\n用户取消操作\n");
                return;
            }
            XData xdata = new XData(id);

            if (!xdata.HasXData())
            {
                Tools.WriteMessage("\n该实体不存在扩展数据\n");
                return;
            }

            string appName = getAppName();//获取appname

            if (appName == null)
            {
                ed.WriteMessage("\n用户取消操作\n");
                return;
            }

            if (!XData.IsAppExist(appName))
            {
                Tools.WriteMessage("\n该应用程序名对应的扩展数据不存在\n");
                return;
            }

            xdata.PrintXData(appName);
        }
Beispiel #17
0
        /// <summary>
        ///     Safe method to acess parameters in context
        /// </summary>
        /// <param name="name"> </param>
        /// <param name="def"> </param>
        /// <param name="setup"> </param>
        /// <typeparam name="T"> </typeparam>
        /// <returns> </returns>
// ReSharper disable OptionalParameterHierarchyMismatch
        public override T Get <T>(string name, T def = default(T), bool setup = false)
        {
// ReSharper restore OptionalParameterHierarchyMismatch
            if (Parameters.ContainsKey(name) || null == XData)
            {
                return(Parameters.GetValue(name, def, initialize: setup));
            }
            var a = XData.Attribute(name);

            if (null != a)
            {
                if (typeof(XAttribute).IsAssignableFrom(typeof(T)))
                {
                    return((T)(object)a);
                }
                return(a.Value.To <T>());
            }
            var e = XData.Element(name);

            if (null != e)
            {
                if (typeof(XElement).IsAssignableFrom(typeof(T)))
                {
                    return((T)(object)e);
                }
                return(e.Value.To <T>());
            }
            return(def);
        }
        public void SaveData(double xStart, double xIncrement, IList <double> yData, int xSize, int ySize, int lineCount)
        {
            DataInfo.XDataInputType = XDataInputType.Increment;
//            DataInfo.XDataType = XDataType.Number;
            XStart        = xStart;
            XIncrement    = xIncrement;
            DataInfo.Size = xSize <= ySize ? xSize : ySize;

            MaxXValue = xStart + (DataInfo.Size - 1) * xIncrement;
            MinXValue = xStart;

            XMinInterval = xIncrement > Constants.MinLegalInterval ? xIncrement : Constants.MinLegalInterval;

            DataInfo.LineNum = lineCount;

            XData?.Clear();
            YData = SaveDataToBuf(YData, yData);

            CheckInvalidData();

            _transBuf = null;

            PlotBuf.AdaptPlotBuffer();

            InitViewRange();
        }
Beispiel #19
0
 public override void SetXmlInstance(object inst, XamlMember property, XData xData)
 {
     if (!MemberAccessPermissionDenied || property.IsReadPublic)
     {
         try
         {
             _transparentRuntime.SetXmlInstance(inst, property, xData);
             return;
         }
         catch (XamlException e)
         {
             if (e.InnerException is MethodAccessException)
             {
                 MemberAccessPermissionDenied = true;
             }
             else
             {
                 throw;
             }
         }
         catch (SecurityException)
         {
             MemberAccessPermissionDenied = true;
         }
     }
     _elevatedRuntime.SetXmlInstance(inst, property, xData);
     return;
 }
Beispiel #20
0
 /// <summary>
 ///     Converts given parameter to string array with splitters
 /// </summary>
 /// <param name="name"> </param>
 /// <param name="splitters"> </param>
 /// <returns> </returns>
 public override string[] GetArray(string name, params char[] splitters)
 {
     splitters = splitters.Length == 0 ? new[] { ',' } : splitters;
     if (Parameters.ContainsKey(name))
     {
         var arraysrc = Parameters[name];
         return(arraysrc.SmartSplit(false, true, splitters).ToArray());
     }
     if (null != XData)
     {
         var a = XData.Attribute(name);
         if (null != a)
         {
             return(a.Value.SmartSplit(false, true, splitters).ToArray());
         }
         var elements = XData.Elements(name).ToArray();
         if (elements.Count() > 1)
         {
             return(elements.Select(x => x.Value).ToArray());
         }
         if (elements.Count() == 1)
         {
             var e = elements.First(x => null != x);
             if (e.Elements().Any())
             {
                 return(e.Elements().Select(x => x.Value).ToArray());
             }
             return(new[] { e.Value });
         }
     }
     return(new string[] {});
 }
        private static void WritePolyline3d()
        {
            DxfDocument dxf = new DxfDocument();

            List <Polyline3dVertex> vertexes = new List <Polyline3dVertex> {
                new Polyline3dVertex(0, 0, 0),
                new Polyline3dVertex(10, 0, 10),
                new Polyline3dVertex(10, 10, 20),
                new Polyline3dVertex(0, 10, 30)
            };

            Polyline3d poly = new Polyline3d(vertexes, true);

            XData xdata = new XData(new ApplicationRegistry("netDxf"));

            xdata.XDataRecord.Add(new XDataRecord(XDataCode.String, "extended data with netDxf"));
            xdata.XDataRecord.Add(XDataRecord.OpenControlString);
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.String, "netDxf polyline3d"));
            xdata.XDataRecord.Add(new XDataRecord(XDataCode.Integer, poly.Vertexes.Count));
            xdata.XDataRecord.Add(XDataRecord.CloseControlString);

            poly.XData = new Dictionary <ApplicationRegistry, XData>
            {
                { xdata.ApplicationRegistry, xdata },
            };
            dxf.AddEntity(poly);

            dxf.Save("polyline.dxf", DxfVersion.AutoCad2000);
        }
Beispiel #22
0
        public bool Parse()
        {
            string[] splitStr = StrSourceData.Split(new char[] { '\r', '\n' });
            string   pattern  = @"^(-?\d+)(\.\d+)?\t(-?\d+)(\.\d+)?$";
            var      RetData  = splitStr.Where(n => Regex.IsMatch(n, pattern));

            if (XData == null)
            {
                XData = new List <double>();
            }
            else
            {
                XData.Clear();
            }
            if (YData == null)
            {
                YData = new List <double>();
            }
            else
            {
                YData.Clear();
            }
            foreach (var strLine in RetData)
            {
                string[] tmp = strLine.Split('\t');
                XData.Add(Convert.ToDouble(tmp[0]));
                YData.Add(Convert.ToDouble(tmp[1]));
            }
            XMin = XData.Min();
            XMax = XData.Max();
            YMax = YData.Max();
            calPercentageData();
            calExtremePoints();
            return(true);
        }
Beispiel #23
0
        public void GetXmlReaderWithNullText()
        {
            var x = new XData();

            Assert.IsNull(x.Text, "#1");
            Assert.IsNull(x.XmlReader, "#2");
        }
Beispiel #24
0
        public List <Poco_I> GetAllFrom(long fromId)
        {
            var api = (AssociationApi_I)XData.GetApi <Association_I>();

            // From type id, get data api
            return(api.GetAllFrom(fromId));
        }
Beispiel #25
0
        public void SetNonXmlReader()
        {
            var       x = new XData();
            XmlReader r;

            x.XmlReader = "<foo/>";                 // not allowed. It does *not* raise an error, but the value becomes null.
            r           = x.XmlReader as XmlReader; // and thus it causes ANE.
        }
 public SimpleFigures(Thickness position, XData data)
 {
     InitializeComponent();
     InitializeComponentData(position, data);
     DrawFigure(data.Type);
     ResizeFiguresCreation();
     ResizeFiguresHide();
 }
Beispiel #27
0
        public void SetNonXmlReader()
        {
            var x = new XData();

            x.XmlReader = "<foo/>";             // not allowed. It does *not* raise an error, but the value becomes null.
                        #pragma warning disable 219
            var r = x.XmlReader as XmlReader;   // and thus it causes ANE.
                        #pragma warning restore 219
        }
Beispiel #28
0
        public void SetXmlReader()
        {
            var x = new XData();

            x.XmlReader = XmlReader.Create(new StringReader("<root/>"));
            Assert.IsNull(x.Text, "#1");
            Assert.IsNotNull(x.XmlReader, "#2");
            x.XmlReader = null;
        }
 public SimpleFigures(Rectangle rect, XData data)
 {
     InitializeComponent();
     InitializeComponentData(rect, data);
     InitializeOnKeyEvents();
     DrawFigure(data.Type);
     ResizeFiguresCreation();
     ResizeFiguresHide();
 }
Beispiel #30
0
 public void GetXmlReaderWithNullText()
 {
     Assert.Throws(typeof(ArgumentNullException), () =>
     {
         var x = new XData();
         Assert.IsNull(x.Text, "#1");
         Assert.IsNull(x.XmlReader, "#2");
     });
 }
Beispiel #31
0
		public void SetNonXmlReader ()
		{
			var x = new XData ();
			x.XmlReader = "<foo/>"; // not allowed. It does *not* raise an error, but the value becomes null.
			#pragma warning disable 219
			Assert.Throws<ArgumentNullException> (() => {
				var r = x.XmlReader as XmlReader; // and thus it causes ANE.
			});
			#pragma warning restore 219
		}
Beispiel #32
0
		public void TextSetsXmlReader ()
		{
			var x = new XData ();
			x.Text = "foobar";
			Assert.IsNotNull (x.Text, "#3");
			var r = x.XmlReader as XmlReader;
			Assert.IsNotNull (r, "#4");
			Assert.AreEqual (XmlNodeType.None, r.NodeType, "#5");
			try {
				r.Read (); // invalid xml
				Assert.Fail ("#6");
			} catch (XmlException) {
			}
		}
Beispiel #33
0
		public void GetXmlReaderWithNullText ()
		{
			var x = new XData ();
			Assert.IsNull (x.Text, "#1");
			Assert.Throws<ArgumentNullException> (() => { var xr = x.XmlReader; }, "#2");
		}
Beispiel #34
0
		public void SetTextNull ()
		{
			var x = new XData ();
			// allowed.
			x.Text = null;
		}
Beispiel #35
0
		public void SetXmlReader ()
		{
			var x = new XData ();
			x.XmlReader = XmlReader.Create (new StringReader ("<root/>"));
			Assert.IsNull (x.Text, "#1");
			Assert.IsNotNull (x.XmlReader, "#2");
			x.XmlReader = null;
		}
Beispiel #36
0
        private void AddDimensionStyleOverridesXData(XDataDictionary xdata, DimensionStyleOverrideDictionary overrides, EntityObject entity)
        {
            XData xdataEntry;
            if (xdata.ContainsAppId(ApplicationRegistry.DefaultName))
            {
                xdataEntry = xdata[ApplicationRegistry.DefaultName];
                xdataEntry.XDataRecord.Clear();
            }
            else
            {
                xdataEntry = new XData(new ApplicationRegistry(ApplicationRegistry.DefaultName));
                xdata.Add(xdataEntry);
            }
            xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.String, "DSTYLE"));
            xdataEntry.XDataRecord.Add(XDataRecord.OpenControlString);
            bool writeDIMPOST = false;
            string prefix = string.Empty;
            string suffix = string.Empty;
            bool writeDIMSAH = false;
            bool writeDIMZIN = false;
            bool writeDIMAZIN = false;
            bool suppressLinearLeadingZeros = false;
            bool suppressLinearTrailingZeros = false;
            bool suppressAngularLeadingZeros = false;
            bool suppressAngularTrailingZeros = false;
            bool suppressZeroFeet = true;
            bool suppressZeroInches = true;
            foreach (DimensionStyleOverride styleOverride in overrides.Values)
            {
                switch (styleOverride.Type)
                {
                    case DimensionStyleOverrideType.DimLineColor:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 176));
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, ((AciColor) styleOverride.Value).Index));
                        break;
                    case DimensionStyleOverrideType.DimLineLinetype:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 345));
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.DatabaseHandle, ((Linetype) styleOverride.Value).Handle));
                        break;
                    case DimensionStyleOverrideType.DimLineLineweight:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 371));
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) (Lineweight) styleOverride.Value));
                        break;
                    case DimensionStyleOverrideType.DimLineExtend:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 46));
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Real, (double) styleOverride.Value));
                        break;
                    case DimensionStyleOverrideType.ExtLineColor:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 177));
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, ((AciColor) styleOverride.Value).Index));
                        break;
                    case DimensionStyleOverrideType.ExtLine1Linetype:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 346));
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.DatabaseHandle, ((Linetype) styleOverride.Value).Handle));
                        break;
                    case DimensionStyleOverrideType.ExtLine2Linetype:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 347));
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.DatabaseHandle, ((Linetype) styleOverride.Value).Handle));
                        break;
                    case DimensionStyleOverrideType.ExtLineLineweight:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 372));
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) (Lineweight) styleOverride.Value));
                        break;
                    case DimensionStyleOverrideType.ExtLine1:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 75));
                        if ((bool) styleOverride.Value)
                            xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 1));
                        else
                            xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 0));
                        break;
                    case DimensionStyleOverrideType.ExtLine2:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 76));
                        if ((bool) styleOverride.Value)
                            xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 1));
                        else
                            xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 0));
                        break;
                    case DimensionStyleOverrideType.ExtLineOffset:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 42));
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Real, (double) styleOverride.Value));
                        break;
                    case DimensionStyleOverrideType.ExtLineExtend:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 44));
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Real, (double) styleOverride.Value));
                        break;
                    case DimensionStyleOverrideType.ArrowSize:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 41));
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Real, (double) styleOverride.Value));
                        break;
                    case DimensionStyleOverrideType.CenterMarkSize:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 141));
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Real, (double) styleOverride.Value));
                        break;
                    case DimensionStyleOverrideType.LeaderArrow:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 341));
                        xdataEntry.XDataRecord.Add(styleOverride.Value != null
                            ? new XDataRecord(XDataCode.DatabaseHandle, ((Block) styleOverride.Value).Record.Handle)
                            : new XDataRecord(XDataCode.DatabaseHandle, "0"));
                        break;
                    case DimensionStyleOverrideType.DimArrow1:
                        writeDIMSAH = true;
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 343));
                        xdataEntry.XDataRecord.Add(styleOverride.Value != null
                            ? new XDataRecord(XDataCode.DatabaseHandle, ((Block) styleOverride.Value).Record.Handle)
                            : new XDataRecord(XDataCode.DatabaseHandle, "0"));
                        break;
                    case DimensionStyleOverrideType.DimArrow2:
                        writeDIMSAH = true;
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 344));
                        xdataEntry.XDataRecord.Add(styleOverride.Value != null
                            ? new XDataRecord(XDataCode.DatabaseHandle, ((Block) styleOverride.Value).Record.Handle)
                            : new XDataRecord(XDataCode.DatabaseHandle, "0"));
                        break;
                    case DimensionStyleOverrideType.TextStyle:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 340));
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.DatabaseHandle, ((TextStyle) styleOverride.Value).Handle));
                        break;
                    case DimensionStyleOverrideType.TextColor:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 178));
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, ((AciColor) styleOverride.Value).Index));
                        break;
                    case DimensionStyleOverrideType.TextHeight:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 140));
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Real, (double) styleOverride.Value));
                        break;
                    case DimensionStyleOverrideType.TextOffset:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 147));
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Real, (double) styleOverride.Value));
                        break;
                    case DimensionStyleOverrideType.DimScaleOverall:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 40));
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Real, (double) styleOverride.Value));
                        break;
                    case DimensionStyleOverrideType.AngularPrecision:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 179));
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) styleOverride.Value));
                        break;
                    case DimensionStyleOverrideType.LengthPrecision:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 271));
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) styleOverride.Value));
                        break;
                    case DimensionStyleOverrideType.DimPrefix:
                        writeDIMPOST = true;
                        prefix = (string) styleOverride.Value;
                        break;
                    case DimensionStyleOverrideType.DimSuffix:
                        writeDIMPOST = true;
                        suffix = (string) styleOverride.Value;
                        break;
                    case DimensionStyleOverrideType.DecimalSeparator:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 278));
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) (char) styleOverride.Value));
                        break;
                    case DimensionStyleOverrideType.DimScaleLinear:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 144));
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Real, (double) styleOverride.Value));
                        break;
                    case DimensionStyleOverrideType.DimLengthUnits:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 277));
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) (LinearUnitType) styleOverride.Value));
                        break;
                    case DimensionStyleOverrideType.DimAngularUnits:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 275));
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) (AngleUnitType) styleOverride.Value));
                        break;
                    case DimensionStyleOverrideType.FractionalType:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 276));
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) (FractionFormatType) styleOverride.Value));
                        break;
                    case DimensionStyleOverrideType.SuppressZeroFeet:
                        writeDIMZIN = true;
                        suppressZeroFeet = (bool) styleOverride.Value;
                        break;
                    case DimensionStyleOverrideType.SuppressZeroInches:
                        writeDIMZIN = true;
                        suppressZeroInches = (bool) styleOverride.Value;
                        break;
                    case DimensionStyleOverrideType.SuppressLinearLeadingZeros:
                        writeDIMZIN = true;
                        suppressLinearLeadingZeros = (bool) styleOverride.Value;
                        break;
                    case DimensionStyleOverrideType.SuppressLinearTrailingZeros:
                        writeDIMZIN = true;
                        suppressLinearTrailingZeros = (bool) styleOverride.Value;
                        break;
                    case DimensionStyleOverrideType.SuppressAngularLeadingZeros:
                        writeDIMAZIN = true;
                        suppressAngularLeadingZeros = (bool) styleOverride.Value;
                        break;
                    case DimensionStyleOverrideType.SuppressAngularTrailingZeros:
                        writeDIMAZIN = true;
                        suppressAngularTrailingZeros = (bool) styleOverride.Value;
                        break;
                    case DimensionStyleOverrideType.DimRoundoff:
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 45));
                        xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) styleOverride.Value));
                        break;
                }
            }

            if (writeDIMSAH)
            {
                xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 173));
                xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 1));
            }

            if (writeDIMPOST)
            {
                xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 3));
                xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.String, this.EncodeNonAsciiCharacters(string.Format("{0}<>{1}", prefix, suffix))));
            }

            if (writeDIMZIN)
            {
                short linSupress = 0;
                if (suppressZeroFeet && suppressZeroInches)
                    linSupress = 0;
                else if (!suppressZeroFeet && !suppressZeroInches)
                    linSupress += 1;
                else if (!suppressZeroFeet && suppressZeroInches)
                    linSupress += 2;
                else if (suppressZeroFeet && !suppressZeroInches)
                    linSupress += 3;

                if (!suppressLinearLeadingZeros && !suppressLinearTrailingZeros)
                    linSupress += 0;
                else if (suppressLinearLeadingZeros && !suppressLinearTrailingZeros)
                    linSupress += 4;
                else if (!suppressLinearLeadingZeros && suppressLinearTrailingZeros)
                    linSupress += 8;
                else if (suppressLinearLeadingZeros && suppressLinearTrailingZeros)
                    linSupress += 12;

                xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 78));
                xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, linSupress));
            }

            if (writeDIMAZIN)
            {
                short angSupress = 3;
                if (suppressAngularLeadingZeros && suppressAngularTrailingZeros)
                    angSupress = 3;
                else if (!suppressAngularLeadingZeros && !suppressAngularTrailingZeros)
                    angSupress = 0;
                else if (!suppressAngularLeadingZeros && suppressAngularTrailingZeros)
                    angSupress = 2;
                else if (suppressAngularLeadingZeros && !suppressAngularTrailingZeros)
                    angSupress = 1;

                xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 79));
                xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, angSupress));
            }

            // this information is only required by the Leader entity
            Leader leader = entity as Leader;
            if (leader != null)
            {
                MText mText = leader.Annotation as MText;
                if (mText != null)
                {
                    xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 70));
                    xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) mText.AttachmentPoint));
                    xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) 77));
                    xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short) leader.TextVerticalPosition));
                }
            }

            xdataEntry.XDataRecord.Add(XDataRecord.CloseControlString);
        }
Beispiel #37
0
        private List<DimensionStyleOverride> ReadDimensionStyleOverrideXData(XData xDataOverrides, EntityObject entity)
        {
            List<DimensionStyleOverride> overrides = new List<DimensionStyleOverride>();
            IEnumerator<XDataRecord> records = xDataOverrides.XDataRecord.GetEnumerator();
            short dimzin = -1;
            short dimazin = -1;
            while (records.MoveNext())
            {
                XDataRecord data = records.Current;

                // the dimension style overrides are stored under the string "DSTYLE"
                if (data.Code == XDataCode.String && string.Equals((string) data.Value, "DSTYLE", StringComparison.OrdinalIgnoreCase))
                {
                    if (records.MoveNext())
                        data = records.Current;
                    else
                        return overrides; // premature end

                    // all style overrides are enclosed between XDataCode.ControlString "{" and "}"
                    if (data.Code != XDataCode.ControlString && (string) data.Value != "{")
                        return overrides; // premature end

                    if (records.MoveNext())
                        data = records.Current;
                    else
                        return overrides; // premature end

                    while (!(data.Code == XDataCode.ControlString && (string) data.Value == "}"))
                    {
                        if (data.Code != XDataCode.Int16)
                            return overrides;
                        short styleOverrideCode = (short) data.Value;
                        if (records.MoveNext())
                            data = records.Current;
                        else
                            return overrides; // premature end

                        // the xData overrides must be read in pairs.
                        // the first is the dimension style property to override, the second is the new value
                        switch (styleOverrideCode)
                        {
                            case 176: // DimensionStyleOverrideType.DIMCLRD:
                                if (data.Code != XDataCode.Int16)
                                    return overrides; // premature end
                                overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.DimLineColor, AciColor.FromCadIndex((short) data.Value)));
                                break;

                            case 345: // DimensionStyleOverrideType.DIMLTYPE:
                                if (data.Code != XDataCode.DatabaseHandle)
                                    return overrides; // premature end
                                Linetype dimltype = this.doc.GetObjectByHandle((string) data.Value) as Linetype;
                                if (dimltype == null)
                                    dimltype = this.doc.Linetypes[Linetype.DefaultName];
                                overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.DimLineLinetype, dimltype));
                                break;

                            case 371: // DimensionStyleOverrideType.DIMLWD:
                                if (data.Code != XDataCode.Int16)
                                    return overrides; // premature end
                                overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.DimLineLineweight, (Lineweight) (short) data.Value));
                                break;

                            case 46: // DimensionStyleOverrideType.DIMDLE:
                                if (data.Code != XDataCode.Real)
                                    return overrides; // premature end
                                overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.DimLineExtend, (double) data.Value));
                                break;

                            case 177: // DimensionStyleOverrideType.DIMCLRE:
                                if (data.Code != XDataCode.Int16)
                                    return overrides; // premature end
                                overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.ExtLineColor, AciColor.FromCadIndex((short) data.Value)));
                                break;

                            case 346: // DimensionStyleOverrideType.DIMLTEX1:
                                if (data.Code != XDataCode.DatabaseHandle)
                                    return overrides; // premature end
                                Linetype dimltex1 = this.doc.GetObjectByHandle((string) data.Value) as Linetype;
                                if (dimltex1 == null)
                                    dimltex1 = this.doc.Linetypes[Linetype.DefaultName];
                                overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.ExtLine1Linetype, dimltex1));
                                break;

                            case 347: // DimensionStyleOverrideType.DIMLTEX2:
                                if (data.Code != XDataCode.DatabaseHandle)
                                    return overrides; // premature end
                                Linetype dimltex2 = this.doc.GetObjectByHandle((string) data.Value) as Linetype;
                                if (dimltex2 == null)
                                    dimltex2 = this.doc.Linetypes[Linetype.DefaultName];
                                overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.ExtLine2Linetype, dimltex2));
                                break;

                            case 372: // DimensionStyleOverrideType.DIMLWE:
                                if (data.Code != XDataCode.Int16)
                                    return overrides; // premature end
                                overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.ExtLineLineweight, (Lineweight) (short) data.Value));
                                break;

                            case 75: // DimensionStyleOverrideType.DIMSE1:
                                if (data.Code != XDataCode.Int16)
                                    return overrides; // premature end
                                overrides.Add((short) data.Value == 0
                                    ? new DimensionStyleOverride(DimensionStyleOverrideType.ExtLine1, false)
                                    : new DimensionStyleOverride(DimensionStyleOverrideType.ExtLine1, true));
                                break;

                            case 76: // DimensionStyleOverrideType.DIMSE2:
                                if (data.Code != XDataCode.Int16)
                                    return overrides; // premature end
                                overrides.Add((short) data.Value == 0
                                    ? new DimensionStyleOverride(DimensionStyleOverrideType.ExtLine2, false)
                                    : new DimensionStyleOverride(DimensionStyleOverrideType.ExtLine2, true));
                                break;

                            case 42: // DimensionStyleOverrideType.DIMEXO:
                                if (data.Code != XDataCode.Real)
                                    return overrides; // premature end
                                overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.ExtLineOffset, (double) data.Value));
                                break;

                            case 44: // DimensionStyleOverrideType.DIMEXE:
                                if (data.Code != XDataCode.Real)
                                    return overrides; // premature end
                                overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.ExtLineExtend, (double) data.Value));
                                break;

                            case 41: // DimensionStyleOverrideType.DIMASZ:
                                if (data.Code != XDataCode.Real)
                                    return overrides; // premature end
                                overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.ArrowSize, (double) data.Value));
                                break;

                            case 141: // DimensionStyleOverrideType.DIMCEN:
                                if (data.Code != XDataCode.Real)
                                    return overrides; // premature end
                                overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.CenterMarkSize, (double) data.Value));
                                break;

                            case 341: // DimensionStyleOverrideType.DIMLDRBLK:
                                if (data.Code != XDataCode.DatabaseHandle)
                                    return overrides; // premature end
                                BlockRecord dimldrblk = this.doc.GetObjectByHandle((string) data.Value) as BlockRecord;
                                overrides.Add(dimldrblk == null
                                    ? new DimensionStyleOverride(DimensionStyleOverrideType.LeaderArrow, null)
                                    : new DimensionStyleOverride(DimensionStyleOverrideType.LeaderArrow, this.doc.Blocks[dimldrblk.Name]));
                                break;

                            case 343: // DimensionStyleOverrideType.DIMBLK1:
                                if (data.Code != XDataCode.DatabaseHandle)
                                    return overrides; // premature end
                                BlockRecord dimblk1 = this.doc.GetObjectByHandle((string) data.Value) as BlockRecord;
                                overrides.Add(dimblk1 == null
                                    ? new DimensionStyleOverride(DimensionStyleOverrideType.DimArrow1, null)
                                    : new DimensionStyleOverride(DimensionStyleOverrideType.DimArrow1, this.doc.Blocks[dimblk1.Name]));
                                break;

                            case 344: // DimensionStyleOverrideType.DIMBLK2:
                                if (data.Code != XDataCode.DatabaseHandle)
                                    return overrides; // premature end
                                BlockRecord dimblk2 = this.doc.GetObjectByHandle((string) data.Value) as BlockRecord;
                                overrides.Add(dimblk2 == null
                                    ? new DimensionStyleOverride(DimensionStyleOverrideType.DimArrow2, null)
                                    : new DimensionStyleOverride(DimensionStyleOverrideType.DimArrow2, this.doc.Blocks[dimblk2.Name]));
                                break;

                            case 340: // DimensionStyleOverrideType.DIMTXSTY:
                                if (data.Code != XDataCode.DatabaseHandle)
                                    return overrides; // premature end
                                TextStyle dimtxtsty = this.doc.GetObjectByHandle((string) data.Value) as TextStyle;
                                if (dimtxtsty == null)
                                    dimtxtsty = this.doc.TextStyles[TextStyle.DefaultName];
                                overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.TextStyle, dimtxtsty));
                                break;

                            case 178: // DimensionStyleOverrideType.DIMCLRT:
                                if (data.Code != XDataCode.Int16)
                                    return overrides; // premature end
                                overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.TextColor, AciColor.FromCadIndex((short) data.Value)));
                                break;

                            case 140: // DimensionStyleOverrideType.DIMTXT:
                                if (data.Code != XDataCode.Real)
                                    return overrides; // premature end
                                overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.TextHeight, (double) data.Value));
                                break;

                            case 147: // DimensionStyleOverrideType.DIMGAP:
                                if (data.Code != XDataCode.Real)
                                    return overrides; // premature end
                                overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.TextOffset, (double) data.Value));
                                break;

                            case 40: // DimensionStyleOverrideType.DIMSCALE:
                                if (data.Code != XDataCode.Real)
                                    return overrides; // premature end
                                overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.DimScaleOverall, (double) data.Value));
                                break;

                            case 179: // DimensionStyleOverrideType.DIMADEC:
                                if (data.Code != XDataCode.Int16)
                                    return overrides; // premature end
                                overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.AngularPrecision, (short) data.Value));
                                break;

                            case 271: // DimensionStyleOverrideType.DIMDEC:
                                if (data.Code != XDataCode.Int16)
                                    return overrides; // premature end
                                overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.LengthPrecision, (short) data.Value));
                                break;

                            case 3: // DimensionStyleOverrideType.DIMPOST:
                                if (data.Code != XDataCode.String)
                                    return overrides; // premature end
                                string dimpost = this.DecodeEncodedNonAsciiCharacters((string) data.Value);
                                string[] textPrefixSuffix = GetDimStylePrefixAndSuffix(dimpost);

                                if (!string.IsNullOrEmpty(textPrefixSuffix[0]))
                                    overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.DimPrefix, textPrefixSuffix[0]));
                                if (!string.IsNullOrEmpty(textPrefixSuffix[1]))
                                    overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.DimSuffix, textPrefixSuffix[1]));

                                break;

                            case 278: // DimensionStyleOverrideType.DIMDSEP:
                                if (data.Code != XDataCode.Int16)
                                    return overrides; // premature end
                                overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.DecimalSeparator, (char) (short) data.Value));
                                break;

                            case 144: // DimensionStyleOverrideType.DIMLFAC:
                                if (data.Code != XDataCode.Real)
                                    return overrides; // premature end
                                overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.DimScaleLinear, (double) data.Value));
                                break;

                            case 277: // DimensionStyleOverrideType.DIMLUNIT:
                                if (data.Code != XDataCode.Int16)
                                    return overrides; // premature end
                                overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.DimLengthUnits, (LinearUnitType) (short) data.Value));
                                break;

                            case 275: // DimensionStyleOverrideType.DIMAUNIT:
                                if (data.Code != XDataCode.Int16)
                                    return overrides; // premature end
                                overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.DimAngularUnits, (AngleUnitType) (short) data.Value));
                                break;

                            case 276: // DimensionStyleOverrideType.DIMFRAC:
                                if (data.Code != XDataCode.Int16)
                                    return overrides; // premature end
                                overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.FractionalType, (FractionFormatType) (short) data.Value));
                                break;
                            case 78: // DIMZIN
                                if (data.Code != XDataCode.Int16)
                                    return overrides; // premature end
                                dimzin = (short) data.Value;
                                break;

                            case 79: // DIMAZIN
                                if (data.Code != XDataCode.Int16)
                                    return overrides; // premature end
                                dimazin = (short) data.Value;
                                break;

                            case 45: // DimensionStyleOverrideType.DIMRND:
                                if (data.Code != XDataCode.Int16)
                                    return overrides; // premature end
                                overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.DimRoundoff, (short) data.Value));
                                break;
                            case 70: // this code is only required by Leader entities
                                Leader leader = entity as Leader;
                                if (leader == null)
                                    break;
                                leader.TextVerticalPosition = (LeaderTextVerticalPosition) (short) data.Value;
                                break;
                        }

                        if (records.MoveNext())
                            data = records.Current;
                        else
                            return overrides; // premature end
                    }
                }
            }

            if (dimzin >= 0)
            {
                // suppress leading and/or trailing zeros
                if (12 - dimzin <= 0)
                {
                    overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressLinearLeadingZeros, true));
                    overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressLinearTrailingZeros, true));
                    dimzin -= 12;
                }
                else if (8 - dimzin <= 0)
                {
                    overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressLinearLeadingZeros, false));
                    overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressLinearTrailingZeros, true));
                    dimzin -= 8;
                }
                else if (4 - dimzin <= 0)
                {
                    overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressLinearLeadingZeros, true));
                    overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressLinearTrailingZeros, false));
                    dimzin -= 4;
                }
                else
                {
                    overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressLinearLeadingZeros, false));
                    overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressLinearTrailingZeros, false));
                }
                // suppress feet and/or inches
                switch (dimzin)
                {
                    case 0:
                        overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressZeroFeet, true));
                        overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressZeroInches, true));
                        break;
                    case 1:
                        overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressZeroFeet, false));
                        overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressZeroInches, false));
                        break;
                    case 2:
                        overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressZeroFeet, false));
                        overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressZeroInches, true));
                        break;
                    case 3:
                        overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressZeroFeet, true));
                        overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressZeroInches, false));
                        break;
                    default:
                        overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressZeroFeet, true));
                        overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressZeroInches, true));
                        break;
                }
            }

            // suppress angular leading and/or trailing zeros
            switch (dimazin)
            {
                case 0:
                    overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressAngularLeadingZeros, false));
                    overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressAngularTrailingZeros, false));
                    break;
                case 1:
                    overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressAngularLeadingZeros, true));
                    overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressAngularTrailingZeros, false));
                    break;
                case 2:
                    overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressAngularLeadingZeros, false));
                    overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressAngularTrailingZeros, true));
                    break;
                case 3:
                    overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressAngularLeadingZeros, true));
                    overrides.Add(new DimensionStyleOverride(DimensionStyleOverrideType.SuppressAngularTrailingZeros, true));
                    break;
            }

            return overrides;
        }
        private void AddHatchPatternXData(Hatch hatch)
        {
            XData xdataEntry;
            if (hatch.XData.ContainsAppId(ApplicationRegistry.DefaultName))
            {
                xdataEntry = hatch.XData[ApplicationRegistry.DefaultName];
                xdataEntry.XDataRecord.Clear();
            }
            else
            {
                xdataEntry = new XData(new ApplicationRegistry(ApplicationRegistry.DefaultName));
                hatch.XData.Add(xdataEntry);
            }
            xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.RealX, hatch.Pattern.Origin.X));
            xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.RealY, hatch.Pattern.Origin.Y));
            xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.RealZ, 0.0));


            HatchGradientPattern grad = hatch.Pattern as HatchGradientPattern;
            if (grad == null) return;
          
            if (hatch.XData.ContainsAppId("GradientColor1ACI"))
            {
                xdataEntry = hatch.XData["GradientColor1ACI"];
                xdataEntry.XDataRecord.Clear();
            }
            else
            {
                xdataEntry = new XData(new ApplicationRegistry("GradientColor1ACI"));
                hatch.XData.Add(xdataEntry);
            }
            xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, grad.Color1.Index));


            if (hatch.XData.ContainsAppId("GradientColor2ACI"))
            {
                xdataEntry = hatch.XData["GradientColor2ACI"];
                xdataEntry.XDataRecord.Clear();
            }
            else
            {
                xdataEntry = new XData(new ApplicationRegistry("GradientColor2ACI"));
                hatch.XData.Add(xdataEntry);
            }
            xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, grad.Color2.Index));
        }
 private void AddLeaderTextPositionXData(Leader leader)
 {
      MText mText = leader.Annotation as MText;
     if (mText != null)
     {
         XData xdataEntry;
         if (leader.XData.ContainsAppId(ApplicationRegistry.DefaultName))
         {
             xdataEntry = leader.XData[ApplicationRegistry.DefaultName];
             xdataEntry.XDataRecord.Clear();
         }
         else
         {
             xdataEntry = new XData(new ApplicationRegistry(ApplicationRegistry.DefaultName));
             leader.XData.Add(xdataEntry);
         }
         xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.String, "DSTYLE"));
         xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.ControlString, "{"));
         xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short)70));
         xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short)mText.AttachmentPoint));
         xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short)77));
         xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short)leader.TextVerticalPosition));
         xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.ControlString, "}"));
     }
 }
        private void AddBlockRecordUnitsXData(BlockRecord record)
        {
            // for dxf versions prior to AutoCad2007 the block record units is stored in an extended data block
            XData xdataEntry;
            if (record.XData.ContainsAppId(ApplicationRegistry.DefaultName))
            {
                xdataEntry = record.XData[ApplicationRegistry.DefaultName];
                xdataEntry.XDataRecord.Clear();
            }
            else
            {
                xdataEntry = new XData(new ApplicationRegistry(ApplicationRegistry.DefaultName));
                record.XData.Add(xdataEntry);
            }

            xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.String, "DesignCenter Data"));
            xdataEntry.XDataRecord.Add(XDataRecord.OpenControlString);
            xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short)1));
            xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, (short)record.Units));
            xdataEntry.XDataRecord.Add(XDataRecord.CloseControlString);
        }
Beispiel #41
0
        private XData ReadXDataRecord(ApplicationRegistry appReg)
        {
            XData xData = new XData(appReg);
            this.chunk.Next();

            while (this.chunk.Code >= 1000 && this.chunk.Code <= 1071)
            {
                if (this.chunk.Code == (short) XDataCode.AppReg)
                    break;

                XDataCode code = (XDataCode) this.chunk.Code;
                object value = null;
                switch (code)
                {
                    case XDataCode.String:
                        value = this.DecodeEncodedNonAsciiCharacters(this.chunk.ReadString());
                        break;
                    case XDataCode.AppReg:
                        // Application name cannot appear inside the extended data, AutoCAD assumes it is the beginning of a new application extended data group
                        break;
                    case XDataCode.ControlString:
                        value = this.chunk.ReadString();
                        break;
                    case XDataCode.LayerName:
                        value = this.DecodeEncodedNonAsciiCharacters(this.chunk.ReadString());
                        break;
                    case XDataCode.BinaryData:
                        value = this.chunk.ReadBytes();
                        break;
                    case XDataCode.DatabaseHandle:
                        value = this.chunk.ReadString();
                        break;
                    case XDataCode.RealX:
                    case XDataCode.RealY:
                    case XDataCode.RealZ:
                    case XDataCode.WorldSpacePositionX:
                    case XDataCode.WorldSpacePositionY:
                    case XDataCode.WorldSpacePositionZ:
                    case XDataCode.WorldSpaceDisplacementX:
                    case XDataCode.WorldSpaceDisplacementY:
                    case XDataCode.WorldSpaceDisplacementZ:
                    case XDataCode.WorldDirectionX:
                    case XDataCode.WorldDirectionY:
                    case XDataCode.WorldDirectionZ:
                    case XDataCode.Real:
                    case XDataCode.Distance:
                    case XDataCode.ScaleFactor:
                        value = this.chunk.ReadDouble();
                        break;
                    case XDataCode.Int16:
                        value = this.chunk.ReadShort();
                        break;
                    case XDataCode.Int32:
                        value = this.chunk.ReadInt();
                        break;
                }

                XDataRecord xDataRecord = new XDataRecord(code, value);
                xData.XDataRecord.Add(xDataRecord);
                this.chunk.Next();
            }

            return xData;
        }
		public void GetXmlReaderWithNullText ()
		{
			var x = new XData ();
			Assert.IsNull (x.Text, "#1");
			Assert.IsNull (x.XmlReader, "#2");
		}
		public void SetNonXmlReader ()
		{
			var x = new XData ();
			x.XmlReader = "<foo/>"; // not allowed. It does *not* raise an error, but the value becomes null.
			#pragma warning disable 219
			var r = x.XmlReader as XmlReader; // and thus it causes ANE.
			#pragma warning restore 219
		}
Beispiel #44
0
        internal void AddPatternXData()
        {
            if (this.XData.ContainsAppId(ApplicationRegistry.DefaultName))
            {
                XData xdataEntry = this.XData[ApplicationRegistry.DefaultName];
                xdataEntry.XDataRecord.Clear();
                xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.RealX, this.Pattern.Origin.X));
                xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.RealY, this.Pattern.Origin.Y));
                xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.RealZ, 0.0));
            }
            else
            {
                XData xdataEntry = new XData(new ApplicationRegistry(ApplicationRegistry.DefaultName));
                xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.RealX, this.Pattern.Origin.X));
                xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.RealY, this.Pattern.Origin.Y));
                xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.RealZ, 0.0));
                this.XData.Add(xdataEntry);
            }

            if (!(this.Pattern is HatchGradientPattern)) return;

            HatchGradientPattern grad = (HatchGradientPattern)this.Pattern;
            if (this.XData.ContainsAppId("GradientColor1ACI"))
            {
                XData xdataEntry = this.XData["GradientColor1ACI"];
                XDataRecord record = new XDataRecord(XDataCode.Int16, grad.Color1.Index);
                xdataEntry.XDataRecord.Clear();
                xdataEntry.XDataRecord.Add(record);
            }
            else
            {
                XData xdataEntry = new XData(new ApplicationRegistry("GradientColor1ACI"));
                xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, grad.Color1.Index));
                this.XData.Add(xdataEntry);
            }

            if (this.XData.ContainsAppId("GradientColor2ACI"))
            {
                XData xdataEntry = this.XData["GradientColor2ACI"];
                XDataRecord record = new XDataRecord(XDataCode.Int16, grad.Color2.Index);
                xdataEntry.XDataRecord.Clear();
                xdataEntry.XDataRecord.Add(record);
            }
            else
            {
                XData xdataEntry = new XData(new ApplicationRegistry("GradientColor2ACI"));
                xdataEntry.XDataRecord.Add(new XDataRecord(XDataCode.Int16, grad.Color2.Index));
                this.XData.Add(xdataEntry);
            }
        }
		public void SetNonXmlReader ()
		{
			var x = new XData ();
			XmlReader r;
			x.XmlReader = "<foo/>"; // not allowed. It does *not* raise an error, but the value becomes null.
			r = x.XmlReader as XmlReader; // and thus it causes ANE.
		}