public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            string str = value as string;
            if (str != null) str = str.Trim();
            if (!string.IsNullOrEmpty(str))
            {
                string[] tokens = str.Split(new[] {';'}, StringSplitOptions.RemoveEmptyEntries);
                double scale = 1.0;
                if (tokens.Length > 1) //it is a scaled font
                {
                    str = tokens[0].Trim();
                    scale = double.Parse(tokens[1], CultureInfo.InvariantCulture);
                }

                if (char.IsLetter(str, 0)) //it is a predefined font
                {
                    if (scale == 1.0) //use CurveStyleFont
                        return new IfcDraughtingPreDefinedCurveFont {Name = str};
                    else //CurveFontStyleAndScale
                        return new IfcCurveStyleFontAndScaling
                                   {
                                       CurveFont = new IfcDraughtingPreDefinedCurveFont {Name = str},
                                       CurveFontScaling = scale
                                   };
                }
                else //it should be CurveFontStyle or a CurveFontStyleAndScale
                {
                    DoubleCollection dc = DoubleCollection.Parse(str);
                    int rem;
                    int patterns = Math.DivRem(dc.Count, 2, out rem);
                    if (rem == 0 && patterns > 0) //we have an even number of stroke patterns
                    {
                        IfcCurveStyleFont font = new IfcCurveStyleFont();
                        for (int i = 0; i < dc.Count; i += 2)
                        {
                            font.PatternList.Add_Reversible(new IfcCurveStyleFontPattern
                                                                {
                                                                    VisibleSegmentLength = dc[i],
                                                                    InvisibleSegmentLength = dc[i + 1]
                                                                });
                        }
                        if (scale == 1.0) //use CurveStyleFont
                            return font;
                        else //CurveFontStyleAndScale
                            return new IfcCurveStyleFontAndScaling {CurveFont = font, CurveFontScaling = scale};
                    }
                }
            }
            return base.ConvertFrom(context, culture, value);
        }
        public override bool Equals(object obj)
        {
            // Check for null
            if (obj == null)
            {
                return(false);
            }

            // Check for type
            if (this.GetType() != obj.GetType())
            {
                return(false);
            }

            // Cast as IfcRoot
            IfcCurveStyleFont root = (IfcCurveStyleFont)obj;

            return(this == root);
        }
Beispiel #3
0
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            string str = value as string;

            if (str != null)
            {
                str = str.Trim();
            }
            if (!string.IsNullOrEmpty(str))
            {
                string[] tokens = str.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                double   scale  = 1.0;
                if (tokens.Length > 1) //it is a scaled font
                {
                    str   = tokens[0].Trim();
                    scale = double.Parse(tokens[1], CultureInfo.InvariantCulture);
                }

                if (char.IsLetter(str, 0)) //it is a predefined font
                {
                    if (scale == 1.0)      //use CurveStyleFont
                    {
                        return new IfcDraughtingPreDefinedCurveFont {
                                   Name = str
                        }
                    }
                    ;
                    else //CurveFontStyleAndScale
                    {
                        return new IfcCurveStyleFontAndScaling
                               {
                                   CurveFont = new IfcDraughtingPreDefinedCurveFont {
                                       Name = str
                                   },
                                   CurveFontScaling = scale
                               }
                    };
                }
                else //it should be CurveFontStyle or a CurveFontStyleAndScale
                {
                    DoubleCollection dc = DoubleCollection.Parse(str);
                    int rem;
                    int patterns = Math.DivRem(dc.Count, 2, out rem);
                    if (rem == 0 && patterns > 0) //we have an even number of stroke patterns
                    {
                        IfcCurveStyleFont font = new IfcCurveStyleFont();

                        for (int i = 0; i < dc.Count; i += 2)
                        {
                            font.PatternList.Add_Reversible(new IfcCurveStyleFontPattern
                            {
                                VisibleSegmentLength   = dc[i],
                                InvisibleSegmentLength = dc[i + 1]
                            });
                        }
                        if (scale == 1.0) //use CurveStyleFont
                        {
                            return(font);
                        }
                        else //CurveFontStyleAndScale
                        {
                            return new IfcCurveStyleFontAndScaling {
                                       CurveFont = font, CurveFontScaling = scale
                            }
                        };
                    }
                }
            }
            return(base.ConvertFrom(context, culture, value));
        }