using System; using System.ComponentModel; using System.Drawing; #if WEB_SERVICE #else using System.Drawing.Design; #endif using System.Globalization; using System.Xml.Serialization; using GeoSigmaDrawLib; using SigmaDrawerStyle; namespace GeoSigma.SigmaDrawerStyle { [XmlRoot("Location")] [TypeConverter(typeof(PropertySorter))] public class CurveLocation : CurveView { /// /// Initializes a new instance of the class. /// public CurveLocation() { TypeName = "桩号"; } [XmlIgnore] [Category("基础属性"), DisplayName("\t\t\t\t\t\t\t步长"), Description("步长"), DefaultValue(1000)] [TypeConverterAttribute(typeof(PropertyDoubleConverter))] public double Step { get { return Locate.Step; } set { Locate.Step = value; } } [XmlIgnore] [Category("基础属性"), DisplayName("\t\t\t\t\t\t尺寸"), Description("尺寸")] [TypeConverter(typeof(PropertySizeConvert))] public SizeF LocateSize { get { SizeF size = new SizeF((float)Base.Width, (float)Base.Height); if (size.Width == 0 && size.Height == 0) { size.Width = 200; size.Height = 200; } return size; } set { Base.Width = value.Width; Base.Height = value.Height; } } [XmlIgnore] [Category("基础属性"), DisplayName("\t\t\t\t\t\t角度"), Description("角度")] [TypeConverterAttribute(typeof(PropertyDoubleConverter))] public double Angle { get { return Base.Angle; } set { Base.Angle = value; } } /// TODO: color private Font _TextFont; [XmlIgnore] [Category("基础属性"), DisplayName("\t\t\t\t\t字体"), Description("字体")] [TypeConverterAttribute(typeof(FontPropertyConvert))] public Font TextFont { get { _TextFont = Font.FromLogFont(FontStyle); return _TextFont; } set { _TextFont = value; //FontStyle=new LogFont(); FontStyle = LogFontConverter.convert(_TextFont); //_TextFont.ToLogFont(FontStyle); } } [XmlIgnore] [Category("基础属性"), DisplayName("\t\t\t\t开始桩号"), Description("开始桩号"), DefaultValue(-1000)] [TypeConverterAttribute(typeof(PropertyDoubleConverter))] public double LocateBegin { get { return Locate.Begin; } set { Locate.Begin = value; } } [XmlIgnore] [Category("基础属性"), DisplayName("\t\t\t结束桩号"), Description("结束桩号"), DefaultValue(-2000)] [TypeConverterAttribute(typeof(PropertyDoubleConverter))] public double LocateEnd { get { return Locate.End; } set { Locate.End = value; } } [XmlElement("Offset")] [Category("基础属性"), DisplayName("\t\t偏移"), Description("偏移")] //[TypeConverterAttribute(typeof(PointPropertyConvert))] public PropertyPoint Offset { get; set; } [Browsable(false)] public LocationBase Base { get; set; } = new LocationBase(); [Browsable(false)] [XmlElement("Font")] public LogFont FontStyle { get; set; } = LogFont.Default; LocationLocate _Locate = new LocationLocate(); [Browsable(false)] //private LocationBase _Locate = new LocationBase(); //[XmlElement("Locate")] [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] public LocationLocate Locate { get => _Locate; set => _Locate = value; } [XmlIgnore] [Category("其它"), DisplayName("\t\t\t\t\t\t\t小数位数"), Description("小数位数")] [TypeConverterAttribute(typeof(PropertyIntConverter))] public int Decision { get { return Other.Decimal; } set { Other.Decimal = value; } } [XmlIgnore] [Category("其它"), DisplayName("\t\t\t\t\t\t类型"), Description("类型"), DefaultValue(1)] [TypeConverter(typeof(Converter.CurveLocationTypeConverter))] public int LocationType { get { return (Other.Style & (int)CurveLocalStyle.PLINE_LOCAT_TYPE_Z) != 0 ? 1 : 0; } set { Other.Style &= ~((int)CurveLocalStyle.PLINE_LOCAT_TYPE_L | (int)CurveLocalStyle.PLINE_LOCAT_TYPE_Z); if (value != 0) { Other.Style |= (int)CurveLocalStyle.PLINE_LOCAT_TYPE_Z; } else { Other.Style |= (int)CurveLocalStyle.PLINE_LOCAT_TYPE_L; } } } [XmlIgnore] [Category("其它"), DisplayName("\t\t\t\t\t桩号取整"), Description("桩号取整"), DefaultValue(true)] [TypeConverter(typeof(Converter.YesNoConverter))] public bool IsInteger { get { return (Other.Style & (int)CurveLocalStyle.PLINE_LOCAT_TO_INT) != 0 ? true : false; } set { if (value == true) { Other.Style |= (int)CurveLocalStyle.PLINE_LOCAT_TO_INT; } else { Other.Style &= ~(int)CurveLocalStyle.PLINE_LOCAT_TO_INT; } } } [XmlIgnore] [Category("其它"), DisplayName("\t\t\t\t统一刻度"), Description("统一刻度")] [TypeConverter(typeof(Converter.YesNoConverter))] public bool IsScaleSame { get { return (Other.Style & (int)CurveLocalStyle.PLINE_LOCAT_SCALEONE) != 0 ? true : false; } set { if (value == true) { Other.Style |= (int)CurveLocalStyle.PLINE_LOCAT_SCALEONE; } else { Other.Style &= ~(int)CurveLocalStyle.PLINE_LOCAT_SCALEONE; } } } [XmlIgnore] [Category("其它"), DisplayName("\t\t\t统一方向"), Description("统一方向")] [TypeConverter(typeof(Converter.YesNoConverter))] public bool IsDirectionSame { get { return (Other.Style & (int)CurveLocalStyle.PLINE_LOCAT_DIRECTION) != 0 ? true : false; } set { if (value == true) { Other.Style |= (int)CurveLocalStyle.PLINE_LOCAT_DIRECTION; } else { Other.Style &= ~(int)CurveLocalStyle.PLINE_LOCAT_DIRECTION; } } } [XmlIgnore] [Category("其它"), DisplayName("\t\t标注在节点"), Description("标注在节点")] [TypeConverter(typeof(Converter.YesNoConverter))] public bool IsOnNode { get { return (Other.Style & (int)CurveLocalStyle.PLINE_LOCAT_NODE) != 0 ? true : false; } set { if (value == true) { Other.Style |= (int)CurveLocalStyle.PLINE_LOCAT_NODE; } else { Other.Style &= ~(int)CurveLocalStyle.PLINE_LOCAT_NODE; } } } [XmlIgnore] [Category("其它"), DisplayName("\t显示首位"), Description("显示首位")] [TypeConverter(typeof(Converter.YesNoConverter))] public bool ShowHeadTail { get { return (Other.Style & (int)CurveLocalStyle.PLINE_LOCAT_HEAD_TAIL) != 0 ? true : false; } set { if (value == true) { Other.Style |= (int)CurveLocalStyle.PLINE_LOCAT_HEAD_TAIL; } else { Other.Style &= ~(int)CurveLocalStyle.PLINE_LOCAT_HEAD_TAIL; } } } [XmlIgnore] [Category("其它"), DisplayName("显示方式"), Description("显示方式")] [TypeConverter(typeof(Converter.LineTypeConverter))] public int CurveType { get { return Other.Style & (int)LineType.PLINE_TYPE_ALL; } set { Other.Style &= ~((int)LineType.PLINE_TYPE_ALL); Other.Style |= value; } } [Browsable(false)] [XmlElement("Other")] public LocationOther Other { get; set; } = new LocationOther(); //Line _line = new Line( new Point(0, 0), new Point(100, 100)); //[XmlIgnore] //[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)] //public Line MyLine //{ // get // { // return _line; // } // set // { // _line = value; // } //} } ////线条类 //[TypeConverter(typeof(LineConverter))] //public class Line //{ // // Line members. // Point P1; // Point P2; // public Point Point1 // { // get // { // return P1; // } // set // { // P1=value; // } // } // public Point Point2 // { // get // { // return P2; // } // set // { // P2=value; // } // } // public Line(Point point1, Point point2) // { // P1=point1; // P2=point2; // } //} ////转换器类 //public class LineConverter : TypeConverter //{ // public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) // { // if (destinationType==typeof(string)) // { // return true; // } // if (destinationType==typeof(InstanceDescriptor)) // { // return true; // } // return base.CanConvertTo(context, destinationType); // } // public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) // { // if (sourceType==typeof(string)) // { // return true; // } // return base.CanConvertFrom(context, sourceType); // } // public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) // { // if (destinationType==typeof(string)&&value!=null) // { // Line t = (Line)value; // string str = t.Point1.X+","+t.Point1.Y+","+t.Point2.X+","+t.Point2.Y; // return str; // } // if (destinationType==typeof(InstanceDescriptor)) // { // ConstructorInfo ci = typeof(Line).GetConstructor(new Type[] { typeof(Point), typeof(Point) }); // Line t = (Line)value; // return new InstanceDescriptor(ci, new object[] { t.Point1, t.Point2 }); // } // return base.ConvertTo(context, culture, value, destinationType); // } // public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) // { // if (value is string) // { // string str = (string)value; // str=str.Trim(); // string[] v = str.Split(','); // if (v.Length!=4) // { // throw new NotSupportedException("Invalid parameter format"); // } // int x1 = 0; // int y1 = 0; // int x2 = 0; // int y2 = 0; // bool res = int.TryParse(v[0], out x1); // if (res==false) throw new NotSupportedException("Invalid parameter format"); // res=int.TryParse(v[1], out y1); // if (res==false) throw new NotSupportedException("Invalid parameter format"); // res=int.TryParse(v[2], out x2); // if (res==false) throw new NotSupportedException("Invalid parameter format"); // res=int.TryParse(v[3], out y2); // if (res==false) throw new NotSupportedException("Invalid parameter format"); // Line line = new Line(new Point(x1, y1), new Point(x2, y2)); // return line; // } // return base.ConvertFrom(context, culture, value); // } // public override bool GetPropertiesSupported(ITypeDescriptorContext context) // { // return true; // //return base.GetPropertiesSupported(context); // } // public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) // { // return TypeDescriptor.GetProperties(value, attributes); // //return base.GetProperties(context, value, attributes); // } //} public class LocationBase { [XmlAttribute("Height")] public double Height { get; set; } = 200; [XmlAttribute("Width")] public double Width { get; set; } = 200; [XmlAttribute("Angle")] public double Angle { get; set; } } public class LocationLocateConvert : TypeConverter { public override bool CanConvertTo(ITypeDescriptorContext context, System.Type destinationType) { if (destinationType == typeof(string)) { return true; } if (destinationType == typeof(LocationLocate)) return true; return base.CanConvertTo(context, destinationType); } public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, System.Type destinationType) { if (destinationType == typeof(System.String) && value != null) { LocationLocate ll = (LocationLocate)value; return "" + ll.Begin + "," + ll.End + "," + ll.Step; } if (destinationType == typeof(LocationLocate)) { return new LocationLocate((LocationLocate)value); } return base.ConvertTo(context, culture, value, destinationType); } public override bool CanConvertFrom(ITypeDescriptorContext context, System.Type sourceType) { if (sourceType == typeof(string)) return true; return base.CanConvertFrom(context, sourceType); } public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value is string) { try { string s = (string)value; string[] lstValue = s.Split(','); LocationLocate ll = new LocationLocate(); ll.Begin = double.Parse(lstValue[0]); ll.End = double.Parse(lstValue[1]); ll.Step = double.Parse(lstValue[2]); return ll; } catch { throw new ArgumentException("输入错误,无法将“" + (string)value + "”转换为 LocationLocate 类型"); } } return base.ConvertFrom(context, culture, value); } public override bool GetPropertiesSupported(ITypeDescriptorContext context) { return true; //return base.GetPropertiesSupported(context); } public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) { return TypeDescriptor.GetProperties(value, attributes); //return base.GetProperties(context, value, attributes); } } [TypeConverterAttribute(typeof(LocationLocateConvert))] public class LocationLocate { /// /// Initializes a new instance of the class. /// public LocationLocate() { } /// /// Initializes a new instance of the class. /// /// public LocationLocate(LocationLocate other) { Begin = other.Begin; End = other.End; Step = other.Step; } [XmlAttribute] [NotifyParentProperty(true)] public double Begin { get; set; } = -1000; [XmlAttribute] [NotifyParentProperty(true)] public double End { get; set; } = -2000; [XmlAttribute] [NotifyParentProperty(true)] public double Step { get; set; } = 1000; } public class LocationOther { [XmlAttribute] public int Style { get; set; } = (int)(CurveLocalStyle.PLINE_LOACT_ALL & CurveLocalStyle.PLINE_LOCAT_TO_INT); [XmlAttribute] public int Decimal { get; set; } } }